def opcion1(password): h = scrypt.using(salt=b'salt', salt_size=1024, rounds=8, block_size=8, parallelism=1, relaxed=True).hash(password) return h
def insert_username_into_database(): try: hashedpwd = scrypt.using(salt_size=64).hash(password) print('Connecting with the database...') unixtime = int(time()) cc.execute(insert_username, (username, hashedpwd, unixtime)) conn.commit() print(f'User {username} successfully inserted.') conn.close() except conn.Error as error: print(f'Error: {error}')
def get_hash(pw): hash_str = scrypt.using(rounds=8).hash(pw) return hash_str
def secure_hash(password, base64_encoded_salt): hash = scrypt.using(salt=base64.b64decode(base64_encoded_salt), rounds=4, block_size=8, parallelism=1).hash(password) return hash
""" scrypt.py Implementacion de scrypt para derivación de contraseñas Inspirado y obtenido de https://passlib.readthedocs.io/en/stable/lib/passlib.hash.scrypt.html """ from passlib.hash import scrypt import datetime password = "******" h = scrypt.using( salt=b'saltsaltsalt', salt_size= 64, # Tamano de los salt generados automaticamente dentro de la funcion rounds=8, #Numero de rondas a usar block_size=32, # Parametro r parallelism= 1, # Nivel de paralelismo a usar (parametro p). Pruebas muestran que a mayor paralelismo, mayor tiempo de procesamiento relaxed= True # Para que corrija automaticamente posibles errores en valores de rondas, salt, etc. ).hash(password) print('Contrasena original: {}'.format(password)) print('Contrasena derivada: {}'.format(h)) print('Verificada: {}'.format(scrypt.verify(password, h)))