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

Alan Bridge
Alan Bridge
1,935 Points

Need help: base64/AES/password encryption coming from my app & i need to get the data decrypted in php,App fine PHP not.

I have on my app a script that takes my password 'mypassword' and the data 'hello world 123' and encrypts that with [hello world 123 AESEncryptWithPassphrase:my password]

then it takes that information and [base64 encode:EncryptsTheAboveData]

my question is how do i do this in reverse in PHP to get the data back.

Any help would go a long way.

1 Answer

If you want to encrypt a password in php you can use password_hash function and to decrypt it you can use the password verify function here's an example below

// To encrypt a password

$pass = "p@ssw0rd";

$encrpt_pass = password_hash($pass);

// This will show you the encrypted password
echo $encrpt_pass;

// To verify the encrypted password

// pretend this is the input of the user for the password field
$pass_Input = "p@ssw0rd""

// If it returns true
if(password_verify($pass_Input,$encrpt_pass)){

     echo "Successful password";
}
else {

    echo "Incorrect password";
}

Hope this helps this is the easiest and a very secure way of securing passwords in PHP