2014-05-23 + HW + Lab20

posted May 23, 2014, 5:38 AM by Samuel Konstantinovich   [ updated May 23, 2014, 7:44 AM ]

A hash function is a one way function. There is no inverse so you cannot undo the operation. 
example of a 1 way function that converts numbers and cannot be reversed is the remainder.
3031%15 -> 1
1000%15 ->10
There is no way to undo the change.

example of a 1 way function that converts strings to values is len.
len("ham") -> 3  
len("fish") -> 4

These are not a very good hash functions because many values have the same hashed value.

Hashing a password is really important if you want to store information securely.

MD5 is a way we will hash passwords:


You can use it this way:

import md5
m= md5.new()

hashed = m.hexdigest()
print s,hashed

Hashed contains the text you would store on a website password database.

Store users and passwords in a plain text file:

Your goal:
1. make a user/password file in the format shown. You can use any separator you choose, like , : ; etc.
2. Make a login page that has a user text field, and a password field, along with a submit button.
3. When you click submit, you should check the user/password file for a matching user and hashed password. If there is a match display 
"You logged in" 
if not 
"username and password do not match"