本文整理汇总了Python中passlib.hash.sha256_crypt.encrypt方法的典型用法代码示例。如果您正苦于以下问题:Python sha256_crypt.encrypt方法的具体用法?Python sha256_crypt.encrypt怎么用?Python sha256_crypt.encrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类passlib.hash.sha256_crypt
的用法示例。
在下文中一共展示了sha256_crypt.encrypt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_password
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def set_password(self, value):
password_config = settings.load().get('password', None)
if password_config and password_config.get('enforce'):
regex = password_config['regex']
rules = password_config.get('rules', [])
if re.match(regex, value) is None:
raise PasswordPolicyError(regex, rules)
self.sha256_hash = sha256_crypt.encrypt(value)
示例2: signup
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def signup():
form = SignupForm(request.form)
if request.method == 'POST' and form.validate():
name = form.name.data
email = form.email.data
username = form.username.data
password = sha256_crypt.encrypt(str(form.password.data))
try:
# Create cursor
cur = mysql.connection.cursor()
cur.execute("INSERT INTO users(name, email, username, password) \
VALUES(%s, %s, %s, %s)", (name, email, username, password))
# Commit to DB
mysql.connection.commit()
# Close connection
cur.close()
flash('You are now signed up', 'success')
except Exception as e:
flash("{}".format(e.args[1]), category='warning')
return(redirect(url_for('home')))
return render_template('signup.html', form=form)
示例3: encrypt
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def encrypt(password):
return sha256_crypt.encrypt(password)
示例4: genpass
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def genpass():
from passlib.hash import sha256_crypt
pw = get_pass()
print(sha256_crypt.encrypt(pw))
示例5: get_hash
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def get_hash(password):
""" Returns a new SHA256 Hash for a password (lower rounds for speed)"""
phash = sha256_crypt.encrypt(password, rounds=100000)
return phash
示例6: get_phash
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def get_phash(passwd):
""" Get a new hashed password """
return sha256_crypt.encrypt(passwd, rounds=100000)
示例7: register
# 需要导入模块: from passlib.hash import sha256_crypt [as 别名]
# 或者: from passlib.hash.sha256_crypt import encrypt [as 别名]
def register():
form = RegisterForm(request.form)
if request.method == 'POST' and form.validate():
name = form.name.data
email = form.email.data
username = form.username.data
password = sha256_crypt.encrypt(str(form.password.data))
# Create cursor
cur = mysql.connection.cursor()
# Execute query
cur.execute("INSERT INTO users(name, email, username, password) VALUES(%s, %s, %s, %s)", (name, email, username, password))
# Commit to DB
mysql.connection.commit()
# Close connection
cur.close()
flash('You are now registered and can log in', 'success')
return redirect(url_for('login'))
return render_template('register.html', form=form)
# User login