#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    Question Password protected site


    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. #2
  3. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    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"
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    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 06:36 PM. Reason: forgot to close code tag
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  6. #4
  7. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by Strike
    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"
    Are you sure? cause i just tried it, ran it.. works perfect
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    14
    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.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    Thanx


    Thanx 2 to all.... i solved by adding a line
    line=line[:-1] in my code before split
  12. #7
  13. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by Strike
    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.
    Ahh ok now i see what you meant, sorry

IMN logo majestic logo threadwatch logo seochat tools logo