简体   繁体   English

检查用户输入的 .txt 文件(Python 2.7.11)

[英]Checking a .txt file for an input by the user (Python 2.7.11)

So i am currently creating a quiz program which requires a really basic authentication.所以我目前正在创建一个需要真正基本身份验证的测验程序。 This is the psuedocode that i have.这是我拥有的伪代码。

Start  
Open UserCredentials.txt (This is where the user ID is stored)  
Get UserID  
If UserID is in UserCredetials.txt( This is the part that i could not figure out how to do)  
..Passtries = 0  
..While passtries != 1  
....Get password  
....If password is UserCredentials.txt( The other part which i couldnt do.)  
......Passtries = 1 (Correct password, it will exit the loop)   
....else  
......Passtries = 0 (wrong password, it will continue looping)  
....WhileEnd

So the problem here is that i could not figure out how to check the UserCredentials.txt file based on what the user has inputted and write the code for it in python.所以这里的问题是我无法弄清楚如何根据用户输入的内容检查 UserCredentials.txt 文件并在 python 中为其编写代码。 (Python 2.7.11) (Python 2.7.11)

Note that in the UserCredentials.txt, the userID and password are stored side by side [Izzaz abc123]注意,在 UserCredentials.txt 中,用户 ID 和密码是并排存储的 [Izzaz abc123]

Also i am still kind off new to python, so go easy on me :)另外,我对 python 还不太熟悉,所以对我放轻松:)
Any help is appreciated.任何帮助表示赞赏。

.you should start to use dict for data container and xml or json for the formatting .你应该开始使用 dict 作为数据容器,使用 xml 或 json 进行格式化

UserCredentials.xml

members_dict:
    User(Name = "izzaz", Passwort: "abc123")
    User(Name = "isssz", Passwort: "asassa")

.start
.open UserCredentials.xml/json
.get members_users
.if user_id_input in members_users continue 
.if user_passwort_input == members[user_id_input][passwort]:

its only a guide how it can work, more information about OrderedDict , Xml Parsing , create simple Xml file它只是一个如何工作的指南,关于OrderedDictXml Parsing 的更多信息, 创建简单的 Xml 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM