当前位置: 首页>>代码示例>>Python>>正文


Python pbkdf2_sha256.encrypt方法代码示例

本文整理汇总了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() 
开发者ID:fportantier,项目名称:vulpy,代码行数:20,代码来源:db.py

示例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) 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:8,代码来源:DatabaseLayer.py

示例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}}) 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:5,代码来源:DatabaseLayer.py

示例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 
开发者ID:marcan,项目名称:hackit,代码行数:8,代码来源:users.py

示例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) 
开发者ID:marcan,项目名称:hackit,代码行数:4,代码来源:users.py

示例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) 
开发者ID:afropolymath,项目名称:papers,代码行数:4,代码来源:models.py

示例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() 
开发者ID:quantopian,项目名称:PenguinDome,代码行数:17,代码来源:save_password.py

示例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 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:33,代码来源:authentication_retrieval_point.py

示例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 
开发者ID:bmbove,项目名称:flask-api-boilerplate,代码行数:5,代码来源:models.py


注:本文中的passlib.hash.pbkdf2_sha256.encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。