當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。