-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbcrypt_encrypt.py
More file actions
40 lines (33 loc) · 1.03 KB
/
bcrypt_encrypt.py
File metadata and controls
40 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# ------------------------------------------------------------
# Clase 140
# Encriptamiento
# pip install bcrypt
# ------------------------------------------------------------
# Importamos la libreria bcrypt
import bcrypt_encrypt
# Texto plano
textoPlano = "password"
print("Texto plano: ", textoPlano)
input()
# Debemos tenerla como bytes
textoPlano = textoPlano.encode()
print("Texto plano en bytes: ", textoPlano)
input()
# Generamos semilla
semilla = bcrypt_encrypt.gensalt()
print("Semilla: ", semilla)
print("Semilla Type: ", type(semilla))
input()
# Hasheamos el texto
textHash = bcrypt_encrypt.hashpw(textoPlano, semilla)
print("Texto hash: ", textHash)
input()
# Ahora vamos a comprobarla, recuerda que pass_hasheada puede prevenir que tu base de datos
print("Comprobando contraseñas...")
print("Texto Plano: ", textoPlano)
print("Texto Hash: ", textHash)
# Verificamos si coinciden con el metodo checkpw
if bcrypt_encrypt.checkpw(textoPlano, textHash):
print("Ok, las contraseñas coinciden")
else:
print("Contraseña incorrecta")