Which function to encrypt / decrypt password

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

iamnobody
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Oct 31, 2012 8:58 pm

Which function to encrypt / decrypt password

Postby iamnobody » Wed Oct 31, 2012 9:03 pm

Hi,

Which PHP function can I use to do encryption and decryption of a password? It should be unique and reversible.

Thank you.

Kind regards,

j

MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: Which function to encrypt / decrypt password

Postby MeroD » Thu Nov 01, 2012 1:59 am

http://www.php.net/manual/en/function.sha1.php

Or:

Code: Select all

<?php
$hashed_password 
crypt('mypassword'); // let the salt be automatically generated

if (crypt($user_input$hashed_password) == $hashed_password) {
   echo 
"Password verified!";
}
?>


http://php.net/manual/en/function.crypt.php

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Which function to encrypt / decrypt password

Postby egami » Fri Nov 02, 2012 9:32 am

md5 may also work for you.

php.net/md5

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Which function to encrypt / decrypt password

Postby seandisanti » Fri Nov 02, 2012 2:10 pm

Why does everyone want to be able to reverse passwords? One way encryption is all that is necessary, because there is never ever ever EVER a reason that you need to know another user's password. All you do by trying to have that functionality is set yourself up to be in a position of liability in the event that your data is compromised because of your insecure practices.
</rant>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron