阅读量:0
L
timerring
i love cipher
L
Who
i love cryptography
Q
该系统的源码如下: ##### source code
from future import annotations
from typing import Dict
import getpass
import hashlib
import os
database: Dict[str, UserPassword] = dict()
class UserPassword:
def __init__(self, in_username, in_password_hash, in_salt):
self.username: str = in_username
self.password_hash: bytes = in_password_hash
self.salt: bytes = in_salt
self.method: str = ‘scrypt’
# define verify\_password function def verify\_password(self, password: str) -> bool: password_ver: bytes = password.encode("utf-8") # use the same salt salt_ver: bytes = self.salt # set corresponding parameters n: int = 4 r: int = 8 p: int = 16 password_hash_ver: bytes = hashlib.scrypt(password_ver, salt=salt_ver, n=n, r=r, p=p) # verify the hash value of the password if password_hash_ver == self.password_hash: return True else: return False
def database_add_item(user: UserPassword) -> None:
if user.username in database:
raise Exception(‘User {}