CoderZone.org

Category: >> PHP Code >> Easy Password Encryption and Decryption Bookmark and Share

<< lastnext >>

Snippet Name: Easy Password Encryption and Decryption

Description: An easy password encrypt/decrypt function.

Also see:
» Encrypted Sessions
» Simple reversible encryption
» Reversible Encryption in PHP
» USER password expiration
» USER password
» Verify Password
» Encrypt and Decrypt without a know...
» Password setup
» Password Strength Tester
» Create Random Password
» Random Pronounceable Passwords
» Pronouncable password generator

Comment: (none)

Author:
Language: PHP
Highlight Mode: PHP
Last Modified: March 28th, 2012

< ?php
// function to get the encrypted user password-
function encrypt_customer_password($paswd)
{
  $mykey=$this->getEncryptKey();
  $encryptedPassword=$this->encryptPaswd($paswd,$mykey);
  return $encryptedPassword;
}
 
// function to get the decrypted user password
function decrypt_customer_password($paswd)
{
  $mykey=$this->getEncryptKey();
  $decryptedPassword=$this->decryptPaswd($paswd,$mykey);
  return $decryptedPassword;
}
 
function getEncryptKey()
{
  return base64_encode('mykeyhere');
}
function encryptPaswd($string, $key)
{
  $result = '';
  for($i=0; $i<strlen ($string); $i++)
  {
	$char = substr($string, $i, 1);
	$keychar = substr($key, ($i % strlen($key))-1, 1);
	$char = chr(ord($char)+ord($keychar));
	$result.=$char;
  }
	return base64_encode($result);
}
 
function decryptPaswd($string, $key)
{
  $result = '';
  $string = base64_decode($string);
  for($i=0; $i<strlen($string); $i++)
  {
	$char = substr($string, $i, 1);
	$keychar = substr($key, ($i % strlen($key))-1, 1);
	$char = chr(ord($char)-ord($keychar));
	$result.=$char;
  }
 
	return $result;
}
 
?>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 11