本文整理匯總了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