#reg.py
#Choose username and password
def regis():
userpass = open("userpass.txt","w")
userpass1 = userpass.write(raw_input("Please select a username: ") + "\n")
password1 = userpass.write(raw_input("Select a password: "))
userpass.close()
#end of reg.py
#login.py
# Should i import reg before this function or is it ok to do it in the function?
# This should read the file and allow you to login if your user and pass match the ones registered
# I am having trouble with these things:
# (A) The login prompt works completely fine with the file already created(registered user and pass)//
# - But not when the file hasn't been written//
# - I am trying to call the regis function (which works) ONLY IF the file has nothing in it/hasn't been created//
# (A-2) if i try to integrate registration into this file, as opposed to an import//
# - everything works as it is supposed to EXCEPT the login loops around on itself and continues to ask//
# - for the information after it has already confirmed it... not sure why, i tried messing with all my loops??
def login():
import reg
begin = open("userpass.txt", "w") # This is here because it would not use regis() if no file was ever created//
#-As opposed to just being an empty file.
username = open("userpass.txt", "r")
username.seek(0,0)
for line in username.readlines():
if line == 0: # - This will not call regis// ??works different when you call for amount of text in a file??
reg.regis()
# opens the files... if there is data in the files it prompts for user and pass
# I have tried to different setups... either it doesn't load at all// when finished it loops the top of login()
username = open("userpass.txt", "r")
username.seek(0,0)
for line in username.readlines():
if line != 0:
username.seek(0,0)
a = username.readline()
username.seek(0,1)
b = username.readline()
e = 0
f = 0
u = raw_input("Username: ") + "\n"
while e == 0:
if u == a:
p = raw_input("Password: ")
while f == 0:
if p == b:
e = 1
f = 1
z = 1
print "You are now logged in as: " + a
else:
f = 0
p = raw_input("Incorrect password... Try Again: ")
else:
u = raw_input("Sorry that is not a registered username... Try again: ") + "\n"
e = 0
login()
raw_input("End of test, press enter.")
Zemeus
0
Newbie Poster
Recommended Answers
Jump to PostMaybe append mode 'a' would be more appropriate than starting with empty file?
Generally easier approach would be to read in all passwords, create new file in except clause if it is first user. Put used usernames in set and check from that if user name is available. After succesfull …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.