博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
模仿网站登录注册
阅读量:4313 次
发布时间:2019-06-06

本文共 2395 字,大约阅读时间需要 7 分钟。

要求:用户第一次登陆需要注册,如果注册的用户名在文件里已经存在则提示输入新的用户名,将注册的信息更新到文件中,密码使用摘要算法计算得的值进行保存

注册成功即可登录,登录要输入用户名和密码,显示验证码,输入验证码成功后就登陆成功,

下一次运行程序时,直接输入用户名密码即可,无需再次注册。

代码如下

import hashlibimport randomimport queryinfodic={}path=r'E:\PYTHON学习\excises\day11\usrinformation.txt'def file_dic(file):    with open(file,'r',encoding='utf-8') as f:        content=f.read()        dic.update(eval(content))def get_md5(passwd):    passwd=passwd.encode(encoding='utf-8')    md5=hashlib.md5()    md5.update(passwd)    return md5.hexdigest()#=================================def dic_file(dictionary):    with open(path,'w',encoding='utf-8') as f:        f.write(str(dictionary))#=================================def display():    print('input 1 登录')    print('input 2 注册')    print('input 3 退出')#==================================def createcode():    res=''    for i in range(4):        num=random.randint(0,9)        word1=chr(random.randint(97,122))        word2=chr(random.randint(65,90))        res+=random.choice([str(num),word1,word2])    return resdef main():    flag = True    while flag:        file_dic(path)      #更新字典        display()        num=input('>>')        if num == '2':            while True:                name=input('请输入用户名: ')                password=input('请输入密码: ')                if name in dic:                    print('用户名已经存在,请重新输入')                else:                    dic[name] = get_md5(password + name + '1234')                    dic_file(dic)                    print('注册成功')                    break        elif num == '1':            while True:                display_code=createcode()                print(display_code)                name = input('请输入用户名:')                password = input('请输入密码: ')                code= input('\033[45m 请输入验证码,不区分大小写:\033[0m')                password = get_md5(password + name + '1234')                if name in dic and password == dic[name]:                        if code.strip().lower() == display_code.strip().lower():                            print('登陆成功')                        # cmd=input('please input command:')                        # queryinfo.second_main(cmd)                            break                        else:                            print('验证码输入错误')                else:                    print('用户名或者密码错误')        elif num == '3':            breakmain()
View Code

 

转载于:https://www.cnblogs.com/yuyang26/p/7059717.html

你可能感兴趣的文章
Android上PhoneGap打包本地网站和在线网站
查看>>
HDU-2052(字符画图问题)
查看>>
jython学习笔记3
查看>>
Web测试
查看>>
模型搭建练习2_实现nn模块、optim、two_layer、dynamic_net
查看>>
使用jQuery开发datatable分页表格插件
查看>>
C语言笔记(枚举)
查看>>
coreseek安装使用
查看>>
苹果电脑提示打不开 因为它来自身份不明的开发者 不能安装下载的苹果软件解决方法...
查看>>
收发ICMP封包,实现ping
查看>>
MySql command line client 命令系列
查看>>
内置函数2
查看>>
扩展 IEnumerable<T>,让它根据另一个集合的顺序来排列
查看>>
mvc4.0添加EF4.0时发生编译时错误
查看>>
第16月第12天 CABasicAnimation 旋转加速
查看>>
Linux下查看Python安装了哪些脚本模块
查看>>
ERROR- 开发常见error
查看>>
Servlet 中文乱码问题及解决方案剖析
查看>>
OO第四次博客总结
查看>>
集合—ArrayList
查看>>