Jump to: navigation, search

Php sha1

From w3cyberlearnings

Contents

PHP function sha1

This function calculates the SHA-1 hash of a string.

Syntax sha1

  • String: input
  • Raw (Option): True (20 character binary format), False (Default- 40 character hex number)
sha1(string, RAW)

SHA1 Encryption

In cryptography, SHA-1 is a cryptographic hash function designed by the United States National Security Agency and published by the United States NIST as a U.S. Federal Information Processing Standard. SHA stands for "secure hash algorithm". The three SHA algorithms are structured differently and are distinguished as SHA-0, SHA-1, and SHA-2. SHA-1 is very similar to SHA-0, but corrects an error in the original SHA hash specification that led to significant weaknesses. The SHA-0 algorithm was not adopted by many applications. SHA-2 on the other hand significantly differs from the SHA-1 hash function.

SHA-1 is the most widely used of the existing SHA hash functions, and is employed in several widely used applications and protocols. In 2005, security flaws were identified in SHA-1, namely that a mathematical weakness might exist, indicating that a stronger hash function would be desirable.[2] Although no successful attacks have yet been reported on the SHA-2 variants, they are algorithmically similar to SHA-1 and so efforts are underway to develop improved alternatives.[3][4] A new hash standard, SHA-3, is currently under development — an ongoing NIST hash function competition is scheduled to end with the selection of a winning function in 2012.

Example 1

<?php

echo sha1('David Secret');
?>

Output

3d2ae5d64fc8af1b61c9986b03ec76625cdec61d

Example 2

<?php

$devid_secret='3d2ae5d64fc8af1b61c9986b03ec76625cdec61d';

if(strcmp(sha1('David Secret'),$devid_secret)==0)
{
	echo 'You can login now!!';
}
else {
	echo 'Illigal entry!!';
}
?>

Output

You can login now!!

Example 3

<?php

$login_name = "[email protected]";
$password = 'y3c#@@$$$CCCC';

$loginPass = $login_name . $password;
$top_secret1 = sha1($loginPass, TRUE);
$top_secret2 = sha1($loginPass, FALSE);

echo $top_secret1;
echo '<br/>';
echo $top_secret2;
?>

Output

ÂuQ^Ï�RzZz†;]ˆ;” �†b
c275515ecf1b527a5a7a863b5d883b940a128662

Example 4

<?php

$name = 'Tommy Tomm';
$top_secret = sha1($name);
$top_10 = substr($top_secret, 0, 10);
echo $top_secret;
echo '<br/>';
echo $top_10;
?>

Output

e303d84226b03b9ccc5b5ae7cf1dabd09055f18b
e303d84226

Related Functions


Navigation
Web
SQL
MISC
References