Encrypting Strings with Crypt()

Creator:
jax

If you have a multi-user website then it is probably good that you have good encryption methods. This tutorial will explain how to encrypt these passwords and then match them with un-encrypted strings when the user comes back. First, you need to encrypt it. This is fairly simple.


<? $password crypt("abc123"); ?>


That will make abc123 a whole bunch of different characters.

Now, lets say you have a user login. So does the user have to put in all those characters and everything? No. They'll just have to put in abc123. It's up to you to match it with the encrypted password and here's how to do it:



<? 
    $cryptpass 
crypt("abc123"); // this is just an example, 
                //normally you would grab this out of the database 
    
$password $_POST['password']; // this is assuming you're having abc123 sent via a form 
        
if(crypt($password$cryptpass) == $cryptpass){ echo 'success'; } 
            else { 
                echo 
'password incorrect.'
        } 
?>

That is the basics of crypt. You will have to set it up your own way to deal with the way your system is set up, but the function doesn't change none the less.

Description:
Encrypt important information using the crypt() function.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options