Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting Passwords

Status
Not open for further replies.

lonnieC4

Programmer
Joined
Oct 4, 2002
Messages
2
Location
US
I have several pages set up for authorized users only. I write the user name and their password to a MySQL database. Everything works fine except I am not encryting anything. How do I do this?
 
When you insert or upate a password in a MySQL table, you can use MySQL's PASSWORD() function by issuing a query like the following. Assume that the new username is "foo" and the new password is "bar", and user credentials are stored in a table called "credentials":

INSERT INTO credentials (username, userpassword) VALUES ('foo', password('bar'))

When you want to verify a set of credentials later handed to your script by a user, issue a command similar to:

SELECT COUNT(username) FROM credentials WHERE username = '<user-provided username>' AND userpassword = PASSWORD('<user-provided password>')

If it finds a set of credentials that match the credentials provided by your user, the last query should return 1. Otherwise it will return 0. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top