python之文件操作用户密码验证
python之文件操作用户密码验证
实现的功能是,根据文件的用户密码,进行输入用户确认
# cat user.txt wei:123 li:111 wang:222 zhang:333 # vim r1.py #!/bin/python3 # -*- coding: utf-8 -*- name=True while name: inp_username=input('you name:').strip() inp_password=input('you password:').strip() with open('user.txt',mode='rt',encoding='utf-8') as f: for line in f: username,password=line.strip().split(':') if inp_username == username and inp_password == password: print('login successfull') name=False break else: print('username or password error') # python3 r1.py you name:wei you password:121 username or password error you name:wei you password:123 login successfull