Jump to: navigation, search

Mysql SHA1

From w3cyberlearnings

Contents

MySQL SHA1 Function

This function calculates an SHA-1 160 bit checksum for a given string and it returns as a string of 40 hex digits.

Syntax SHA1

  • str: string
SHA1(str);

Example 1

mysql> SELECT SHA1('good');
+------------------------------------------+
| SHA1('good')                             |
+------------------------------------------+
| fc19318dd13128ce14344d066510a982269c241b | 
+------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT SHA('good');
+------------------------------------------+
| SHA('good')                              |
+------------------------------------------+
| fc19318dd13128ce14344d066510a982269c241b | 
+------------------------------------------+
1 row in set (0.00 sec)

Example 2

mysql> INSERT INTO userpassword(username, password)
    -> VALUES('Romney',SHA1('great'));
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM userpassword;
+----+----------+------------------------------------------+
| id | username | password                                 |
+----+----------+------------------------------------------+
|  1 | Romney   | fbc8fae6b1390136c802d43f16890134bfe73df7 | 
+----+----------+------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM userpassword WHERE password=SHA1('great');
+----+----------+------------------------------------------+
| id | username | password                                 |
+----+----------+------------------------------------------+
|  1 | Romney   | fbc8fae6b1390136c802d43f16890134bfe73df7 | 
+----+----------+------------------------------------------+
1 row in set (0.00 sec)

Related Links


Navigation
Web
SQL
MISC
References