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 trial

PHP

PHP Crypt return *0?

I am the encrypting the password with the crypt function. I have given the Salt value something like this in the database.

randSalt - $2y$10$iusesomecrazystring22 // Database name randSalt

$salt = $row['randSalt'];

$password = crypt($password, $salt)

But when the user submits the form, it's always showing me *0 return in the password field of the database. I am using PHP version 5.6.20 Kindly help me

Simon Coates
Simon Coates
28,694 Points

you should be able to debug the password snippet - possibly using a sandbox for quick response (http://sandbox.onlinephpfunctions.com/). If the password generation is okay with test values, then maybe you're seeing faulty database population. Irrespective, you can break these down and test them separately. you don't need real values to test an insert to the database, and you don't need a database to test password generation.

update: sorry i thought the asterisk was just a random character. From looking at this, i appreciate it's probably an actual response.

1 Answer

Simon Coates
Simon Coates
28,694 Points

I think your salt string is too short. Example generate hash code at https://www.sitepoint.com/password-hashing-in-php/ seems to have 22 characters after the $. I don't really understand the crypt method but it seems to behave different if you shorten the string or add a $ at the end (seems to accept a shorter string, but doesn't apply crypt). I get back *0 when using a too-short string with no trailing $.

Finally, it works, don't know how, but works lol.

Actually, I forget to remove 0 from the user_id database and that is conflicting the other randsalt values. But now everything was setup fine.

Thanks mate for the reply.