Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Söder
7,428 PointsIs this how you hash a password correctly? PHP+MYSQL
Hi!
I'm kind of new to the whole php, mysql safety thinking. I'm currently building a site for my dad, which needs an admin panel. I'm trying to make it somewhat secure.
First thing I did was echoing out password_hash('therealpassword', PASSWORD_DEFAULT), then copy+paste the result into the database where the pass goes (also making sure max characters are set to 255, since I'm using PASSWORD_DEFAULT).
I also stored the hashed password into $stored_password in the php login file for comparison with userinput stored in $password.
Then I verify the userinput with the password in the database:
if(password_verify("$password", $stored_password){
//sql, session, header etc.
}
I also used mysqli_real_escape_string on the user input after storing them in variables and before using them in the sql-statements.
Am I on the right track here?
Thanks.
2 Answers
thomascawthorn
22,986 PointsAre you using composer in this project?
Jonathan Söder
7,428 Pointsbumpity bump
Jonathan Söder
7,428 PointsJonathan Söder
7,428 PointsNo. But I got the answer in a similar thread. I appreciate it though!