5.1 模块

MD5模块

对指定的 “字符串” 进行加密。

import hashlib

def get_md5(data):
    obj = hashlib.md5()  #加盐
    obj.update(data.encode('utf-8'))
    result = obj.hexdigest()
    return result
val = get_md5('123')
print(val)

应用:

import hashlib

USER_LIST = []
def get_md5(data):
    obj = hashlib.md5("12:;idrsicxwersdfsaersdfsdfresdy54436jgfdsjdxff123ad".encode('utf-8'))
    obj.update(data.encode('utf-8'))
    result = obj.hexdigest()
    return result

def register():
    print('**************用户注册**************')
    while True:
        user = input('请输入用户名:')
        if user == 'N':
            return
        pwd = input('请输入密码:')
        temp = {'username':user,'password':get_md5(pwd)}
        USER_LIST.append(temp)

def login():
    print('**************用户登陆**************')
    user = input('请输入用户名:')
    pwd = input('请输入密码:')
    for item in USER_LIST:
        if item['username'] == user and item['password'] == get_md5(pwd):
            return True

register()
result = login()
if result:
   print('登陆成功')
else:
    print('登陆失败')

终端不显示密码

import getpass

pwd = getpass.getpass('请输入密码:')
if pwd == '123':
    print('输入正确')

os模块

sys模块

time模块(三种类型)

datetime和timezone(了解)

hashlib

random

getpass

time

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注