txt file to dictionary and login implementation Python 3 -


i attempting create login script. have usernames , passwords in text file want python read , check through find usernames , passwords.

the biggest problem having "attaching" password username. can scan whole of document both not attached each other.

#------------------------------------------------------------------------------- # name:        login # purpose:      logging in # # author:      dark ariel7 # # created:     19/02/2013 # copyright:   (c) dark ariel7 2013 # licence:     take no responsability anything. #------------------------------------------------------------------------------- getpass import getpass time import sleep database = open("c:\\users\dark ariel7\\desktop\\usb backup\\scripts\\database.txt", encoding='utf-8') username = ("") password = () def login():     database = open("c:\\users\dark ariel7\\desktop\\usb backup\\scripts\\database.txt", encoding='utf-8')     data = (database.read())     username = ("")     password = ()     username = input("username: ")     password = getpass(str("password: "))     login= ",".join((username,password))     if login in data:         print("welcome, " + username)         sleep(3)         pass     else:         print("failed, sucker!")         sleep(5)         exit()  login() 

if guys me figure out .join part great. should make dictionary , use index login sheet? want general feedback on how make code better.

this txt file reading:

[dark ariel7,123456] [poop,anko] 

*edit sorry guys forgot mention using python 3 not 2. far. quick replies. after last else instead of exit put function loops until right username password combo?

the ".join" part joins username , password user types in comma between them (i.e. poop,anko) because that's format in it's stored in database, can search way.

here's code, edited bit, comments functionality , style.

from getpass import getpass time import sleep database = open("c:\\users\dark ariel7\\desktop\\usb backup\\scripts\\database.txt", encoding='utf-8') # these next 2 lines aren't necessary - these variables never used; may want read namespaces:  http://bytebaker.com/2008/07/30/python-namespaces/ #username = ("") #password = () def login():     database = open("c:\\users\dark ariel7\\desktop\\usb backup\\scripts\\database.txt", encoding='utf-8') #   removed parentheses; have no effect here.  putting parens around lone statements doesn't have effect in python.     data = database.read() #   these next 2 lines pointless, because subsequently overwrite values give these variables.  looks you're trying "declare" variables, in java, isn't necessary in python. #   username = ("") #   password = () #   changed "input" "raw_input" because input else don't want.     username = raw_input("username: ")     password = getpass(str("password: "))     login= ",".join((username,password))     if login in data:         print("welcome, " + username) #   not sure why want script sleep, assume have reasons?         sleep(3) #   no need pass #       pass     else:         print("failed, sucker!")         sleep(5) #   exit() isn't necessary - function end itself. #       exit()  login() 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -