通过使用Python语言,什么是生成促销代码的巧妙/有效的方式。 喜欢用于生成折扣优惠券的特殊号码。 如:1027828-1
谢谢
By using python language, what would be a clever / efficient way of generating promotion codes. Like to be used for generating special numbers for discount coupons. like: 1027828-1
Thanks
最满意答案
1027828-1是非常小的。 攻击者只需使用几行代码就可以进行百万次猜测,也可能几天。
这是一个很好的方式来产生一个难以预测的数字使用python,它在Linux和Windows下工作。 它基于64位的二进制安全性,取决于你在做什么,你可能想要urllib.urlencode(),但我会避免base10,因为它没有存储尽可能多的信息。
import os import base64 def secure_rand(len=8): token=os.urandom(len) return base64.b64encode(token) print(secure_rand())作为一个方面说明,这是生成一个完整的字节,这是base256。 256 ^ 8是18446744073709551616,应该足够大。
1027828-1 is extremely small. An attacker can make a ~million guesses using only a couple lines of code and maybe a few days.
This is a good way to produce a hard to predict number using python, it works under linux and windows. It is base64'ed for binary safety, depending what you are doing with it you might want to urllib.urlencode() but I would avoid base10 because it doesn't store as much information.
import os import base64 def secure_rand(len=8): token=os.urandom(len) return base64.b64encode(token) print(secure_rand())As a side note this is generating a full byte, which is base256. 256^8 is 18446744073709551616 which should be large enough.
更多推荐
发布评论