Monday, 22 February 2016

SHA1 PHP encryption function

SHA1 accept a string as a key and return hash string which is encrypted. For decryption key is required, which is used in the encryption.


string sha1 ( string $str [, bool $raw_output = false ] )

If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20, otherwise the returned value is a 40-character hexadecimal number.

Note: Secure password hashing

It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See here for details.

example : 

die("Could not connect to database! ".mysql_error($conn));
$quary="insert into users values(NULL,'$user_name','$password')" or die("error in making sql");
mysql_query($quary) or die("unable to run sql quary");
$msg="User name password saved";

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SHA1 Function Demo : Girfa</title>

<h1>Create Hash Code : Girfa</h1><hr /><br />
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
User Name : <input type="text" name="user" /><br /><br />
Password : <input type="text" name="pass"  /><br /><br />
<input type="submit" name="submit"  value="Save" /><br />
<h3><?php echo $msg;?></h3>