登录注册的python代码_Python简单的登录注册代码

#-*- coding: utf-8 -*-

import hashlib

# 定义数据库(声明字典)

#注册登录的简单hash处理

db={}

def get_md5(password):

md5=hashlib.md5()

#此处密码hash加密处理

md5.update(password.encode(‘utf-8‘))

return md5.hexdigest()

def register(username,password):

pwd=db.get(username,-1)

if pwd==-1:

db[username]=get_md5(username+password+‘123456‘)

print(‘注册成功!‘)

print(‘user:%s‘%username)

print(‘md5:%s‘%db[username])

else:

print(‘用户已经存在!‘)

def login(username,password):

pwd=db.get(username,-1)#db.get()方法是获取value,若不存在返回-1

if pwd==-1:

print(‘用户不存在!‘)

elif get_md5(username+password+‘123456‘)!=pwd:

print(‘用户名或密码不正确!‘)

else:

print(‘欢迎您,%s‘%username)

print(‘开始注册!‘)

user=input(‘user:‘)

password=input(‘password:‘)

register(user,password)

print(‘开始登陆!‘)

user=input(‘user:‘)

password=input(‘password:‘)

login(user,password)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值