python实现模拟身份验证服务器综合系统设计_模拟生成身份信息及查验身份python

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 {}

  • 21
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值