import base64
import os
import hashlib
#print(hashlib.sha256(b'password').hexdigest())
user_name = 'user1'
user_pass = 'password'
db = {}
salt = base64.b64encode(os.urandom(32))
def get_digest(password):
password = bytes(password, 'utf-8')
digest = hashlib.sha256(salt + password).hexdigest()
for _ in range(10000):
digest = hashlib.sha256(bytes(digest, 'utf-8')).hexdigest()
print(digest)
print(digest)
return digest
#上記関数を下記で置き換えることもできる
#digest = hashlib.pbkdf2_hmac('sha256', bytes(user_pass, 'utf-8'), salt, 10000)
db[user_name] = get_digest(user_pass)
def is_login(user_name, password):
return get_digest(password) == db[user_name]
print(is_login(user_name, user_pass))
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme