Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

python - Python用户名和密码(Python Username and Password)

I have to make a Landmark Credit Union in their online banking department.

(我必须在其网上银行部门中建立一个Landmark信用合作社。)

And so I'm trying to create a username and password verification/ creation program for the online service.

(因此,我正在尝试为在线服务创建用户名和密码验证/创建程序。)

Here is the problem:

(这是问题所在:)

When choosing a username and password, a client must enter a valid email address for their username (must contain an “@” symbol, must contain a “.”, and must contain a “.com” or “.edu”).

(在选择用户名和密码时,客户端必须为其用户名输入有效的电子邮件地址(必须包含“ @”符号,必须包含“。”,并且必须包含“ .com”或“ .edu”)。)

When choosing a valid password, the client must have ALL of the following: At least one (1) capital letter, be at least nine (9) characters long, and must contain one (1) special character.

(选择有效的密码时,客户端必须具有以下所有内容:至少一(1)个大写字母,至少九(9)个字符,并且必须包含一(1)个特殊字符。)

If a client enters an incorrect username, the program must respond with an appropriate message asking them to try again.

(如果客户端输入了错误的用户名,则程序必须以适当的消息作为响应,要求他们重试。)

If a client enters an incorrect password, the program must respond with an appropriate message asking them to try again.

(如果客户端输入了错误的密码,则程序必须以适当的消息作为响应,要求他们重试。)

Make a list of two usernames and passwords as an example of stored data that cannot be replicated, as they already belong to another client.

(列出两个用户名和密码,作为无法复制的存储数据的示例,因为它们已经属于另一个客户端。)

But I am having trouble containing the must-haves.

(但是我在包含必需品方面遇到了麻烦。)

File > Username.txt 'r' is:

(文件> Username.txt'r'为:)

Username 1 > CaptainMarvel25, Password 1 > AnythingisPossible25
Username 2 > Thor7, Password 2 > AllMightyThor7

but when I type the username it says define CaptainMarvel25.

(但是当我输入用户名时,它说定义CaptainMarvel25。)

help

(救命)

import csv

def main():
    with open("Usernames.txt","r") as file:
        file_reader = csv.reader(file)
        user_find(file_reader)
        file.close()

def user_find(file):
    user = input("Enter your username: ")
    for row in file:
        if row[0] == user:
            print("username found", user)
            user_found = [row[0],row[1]]
            pass_check(user_found)
            break
        else:
            print("not found")

def pass_check(user_found):
    user = input("enter your password: ")
    if user_found[1] == user:
        print("password match")
    else:
        print("password not match")
        user_find(file_reader)

main()
  ask by KitKat G translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You'll need regex's to match your requirements, here is one way in Python to do that which I think will help you get started:

(您需要使用正则表达式来满足您的要求,这是Python中执行此操作的一种方法,我认为这将帮助您入门:)

# Pattern for special characters
pat = r'(?=.[!@#$%^&])' 

type(re.search(pat,'3fdssr2$3')) == re.Match                                                                                                                           
True

type(re.search(pat,'3fdssr223')) == re.Match                                                                                                                           
False

I hope this helps get you started.

(我希望这可以帮助您入门。)

Search the web for different regex patterns and you should find one for each of your cases.

(在网络上搜索不同的正则表达式模式,您应该为每种情况找到一个。)

You can test at regex101.com

(您可以在regex101.com上进行测试)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...