Python随机生成密码
发表于:2024-11-24 作者:热门IT资讯网编辑
编辑最后更新 2024年11月24日,废话不说,直贴代码# coding:utf-8""" Author : han Email : [email protected] Time : 20
废话不说,直贴代码
# coding:utf-8""" Author : han Email : [email protected] Time : 2019-07-27 17:12 Home Team : Golden State Warriors 随机生成 密码 6位 ~ 20位 三个等级"""import sysimport randomimport stringdef main(d='6', level='1'): """ :param int d: digit(密码位数) :param int level: level(密码复杂度) :return: """ digit = int(d) # 密码位数 6~20 if not (6 <= digit <= 20): return '密码位数error' # 选择密码复杂度 if level == '1': parents = string.digits elif level == '2': parents = ''.join((string.ascii_letters, string.digits)) elif level == '3': parents = ''.join((string.ascii_letters, string.digits, '!@#$%^&*')) else: return '密码复杂度error' pwd = '' for i in range(digit): pwd = ''.join((pwd, random.choice(parents))) print('Password: ', pwd)if __name__ == '__main__': a = sys.argv if len(a) == 3: main(a[1], a[2]) else: print('Use: python produce_pwd.py num level')
https://github.com/oaixnah/pwd