|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi i am making password protected site....
user and pass are stored in text file like this.... user1:word1 user2:word2 user3:word3 ...... i made this pass=open("password.txt", 'r') lines=pass.readlines() pass.close() for line in lines : combo=string.splite(line, ":") if((id==combo[0])and(passwd==combo[1]): return "correct_pass" else: return "wrong_pass" This only work to last user others gives me wrong password somebody have ideia.... ??? thanx |
|
#2
|
||||
|
||||
|
I dont know what id is.. but you should try something like
Code:
for lines in file( 'passwd.txt' ):
( User, Pass ) = lines.strip( ).split( ':' )
if(( id == User ) and ( passwd == Pass )):
print "Correct, You may pass"
else:
print "Intruder Alert"
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#3
|
|||
|
|||
|
That produces a lot of false negatives. Try this instead:
Code:
matched = False
# assuming id is already set to the username and passwd to the password (both to be
# checked against the file listing)
for line in file('passwd.txt'):
user, pass = line.strip().split(':')
if (user == id) and (pass == passwd):
matched = True
break
if matched:
print "Success"
else:
print "Failure"
Last edited by Strike : June 8th, 2004 at 05:36 PM. Reason: forgot to close code tag |
|
#4
|
||||
|
||||
|
Quote:
Are you sure? cause i just tried it, ran it.. works perfect |
|
#5
|
|||
|
|||
|
Yes, yours will print a message for every line in the password file. So unless you have only one entry in there, it will always produce at least one false negative for valid user/pass combos.
|
|
#6
|
|||
|
|||
|
Thanx
Thanx 2 to all.... i solved by adding a line
line=line[:-1] in my code before split |
|
#7
|
||||
|
||||
|
Quote:
Ahh ok now i see what you meant, sorry ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Password protected site |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|