How to do python user verification

藏色散人
Release: 2019-07-06 10:58:49
Original
3912 people have browsed it

How to do python user verification

How to authenticate python users?

python user login verification

Login verification, three chances, how to do it?

1. A user list records legal passwords and usernames, a black room list records users who entered incorrectly 3 times,

an intermediate list records all user inputs, and counts whether a certain user Entered incorrectly 3 times

2. Use in to determine whether an element is in a list, and the for loop holds the input verification

#!/usr/bin/python3
 
__author__ = 'beimenchuixue'
__blog__ = 'http://www.cnblogs.com/2bjiujiu/'
 
 
def login(users_ku):
    lock_list = []                              # 锁定用户库,3次登录失败进入的小黑屋
    median = []                                 # 登录失败的录入中间列表,如果用count数出3次,进入锁定
    while True:
        name = input('输入你的用户名:')
        psw = input('请输入你的密码:')
         
        if name in lock_list:                   # 判断用户是否进入小黑屋
            print('此账号锁定,不能再用此账号登陆')
            continue
        if [name, psw] in users_ku:             # 判断用户输入的合法性
            print('登录成功')
            break
        else:
            median.append(name)                 # 用户名录入
            print('账号或者密码输入错误,请重新输入')
        if median.count(name) == 3:             # 同用户3次登录失败进入的小黑屋
            lock_list.append(name)              # 进入小黑屋
 
 
if __name__ == '__main__':
    # 用户验证密码库
    users_ku = [['name1', 'psw1'], ['name2', 'psw2']] 
    login(users_ku)
Copy after login

Requirements met:

1. User Different input orders can catch whether you enter 3 times

2. If you enter incorrectly 3 times, you will no longer be allowed to log in

Related recommendations: "Python Tutorial

The above is the detailed content of How to do python user verification. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template