2014-05-23 + HW + Lab20

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

Hashing:
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:

https://docs.python.org/2/library/md5.html

You can use it this way:

import md5
m= md5.new()


s="Hello"
m.update(s)
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:
bob:bobbypiggy@gmail.com:5a6d311c0d8f6d1dd03c1c129061d3b1
dave:mib@aol.com:827ccb0eea8a706c4c34a16891f84e7b

Lab20
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"

Comments