本文整理汇总了Python中passlib.hash.pbkdf2_sha256.encrypt方法的典型用法代码示例。如果您正苦于以下问题:Python pbkdf2_sha256.encrypt方法的具体用法?Python pbkdf2_sha256.encrypt怎么用?Python pbkdf2_sha256.encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类passlib.hash.pbkdf2_sha256
的用法示例。
在下文中一共展示了pbkdf2_sha256.encrypt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: db_init
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def db_init():
users = [
('admin', pbkdf2_sha256.encrypt('123456')),
('john', pbkdf2_sha256.encrypt('Password')),
('tim', pbkdf2_sha256.encrypt('Vaider2'))
]
conn = sqlite3.connect('users.sqlite')
c = conn.cursor()
c.execute("DROP TABLE users")
c.execute("CREATE TABLE users (user text, password text, failures int)")
for u,p in users:
c.execute("INSERT INTO users (user, password, failures) VALUES ('%s', '%s', '%d')" %(u, p, 0))
conn.commit()
conn.close()
示例2: addUser
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def addUser(user, pwd, admin=False, localOnly=False):
hashed = pbkdf2_sha256.encrypt(pwd, rounds=hash_rounds, salt_size=salt_size)
entry = {'username':user, 'password':hashed}
if admin: entry['master']= True
if localOnly: entry['local_only']= True
colUSERS.insert(entry)
示例3: changePassword
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def changePassword(user, pwd):
hashed = pbkdf2_sha256.encrypt(pwd, rounds=hash_rounds, salt_size=salt_size)
colUSERS.update({'username': user}, {'$set': {'password': hashed}})
示例4: __init__
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def __init__(self, username, password, pubname, email, seat=None):
self.username = username
self.password = pbkdf2_sha256.encrypt(password)
self.pubname = pubname
self.email = email
self.seat = seat
示例5: changepassword
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def changepassword(self, pwd):
self.password = pbkdf2_sha256.encrypt(pwd)
示例6: hash_password
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def hash_password(password):
return pbkdf2_sha256.encrypt(password, rounds=200000, salt_size=16)
示例7: main
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def main():
args = parse_args()
if not args.password:
args.password = getpass.getpass('Password:')
password2 = getpass.getpass('Confirm password:')
if args.password != password2:
sys.exit('Passwords do not match')
if args.setting:
setting_path = 'server_auth:{}:passwords:{}'.format(
args.setting, args.USERNAME)
else:
setting_path = 'users:{}'.format(args.USERNAME)
hashed = pbkdf2_sha256.encrypt(args.password, rounds=200000, salt_size=16)
set_setting(setting_path, hashed)
save_settings()
示例8: hash_passwords
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def hash_passwords(self, data):
"""Change the content of the users database"""
import time
#TODO: remove printing passwords into log
_log.debug("hash_passwords\n\tdata={}".format(data))
updates_made = False
start = time.time()
for username in data:
user_data = data[username]
try:
is_pbkdf2 = pbkdf2_sha256.identify(user_data['password'])
except Exception as err:
_log.error("Failed to identify if password is PBKDF2 or not:"
"\n\tusername={}"
"\n\tuser_data={}"
"\n\terr={}".format(username, user_data, err))
raise
#If the password is in clear, let's hash it with a salt and store that instead
if ('password' in user_data) and not (is_pbkdf2):
try:
hash = pbkdf2_sha256.encrypt(user_data['password'], rounds=200000, salt_size=16)
except Exception as err:
_log.error("Failed to calculate PBKDF2 of password, err={}".format(err))
raise
user_data['password']=hash
updates_made = True
_log.debug("hashed_passwords"
"\n\tdata={}"
"\n\ttime it took to hash passwords={}".format(data, time.time()-start))
return updates_made
示例9: set_password
# 需要导入模块: from passlib.hash import pbkdf2_sha256 [as 别名]
# 或者: from passlib.hash.pbkdf2_sha256 import encrypt [as 别名]
def set_password(self, password):
self.password = pbkdf2_sha256.encrypt(password)
return self.password