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:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.