使用python生成促销代码(generating promotion code using python)

编程入门 行业动态 更新时间:2024-10-23 17:29:24
使用python生成促销代码(generating promotion code using python)

通过使用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.

更多推荐

本文发布于:2023-07-16 12:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   python   generating   code   promotion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!