
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Data Type for Hashed Password Field in MySQL
The hashed password data type depends upon which hashing algorithm we are using. The hashing algorithm does not depends upon the input size because it produces a result of the same length. It gives the result in a series of hexadecimal digits, and we can reduce the hexadecimal digits by half with the help of UNHEX() function.
There are various algorithms and data types to store values.
MD5 − It can use char(32) or BINARY(16).
SHA-1 − It can use data type char(40) or BINARY(20).
Example of MD5
The following is an example −
mysql> select MD5('This is a hashed password');
Here is the output.
+----------------------------------+ | MD5('This is a hashed password') | +----------------------------------+ | e9d4c42db40abbb4724a0047f7e91e67 | +----------------------------------+ 1 row in set (0.03 sec)
To know the length of the hashed password.
mysql> Â SELECT CHARACTER_LENGTH(MD5('This is a hashed password')); +----------------------------------------------------+ | CHARACTER_LENGTH(MD5('This is a hashed password')) | +----------------------------------------------------+ | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 32 | +----------------------------------------------------+ 1 row in set (0.04 sec)
Example of SHA-1
mysql> select SHA1('This is a hashed password');
The following is the output.
+------------------------------------------+ | SHA1('This is a hashed password') Â Â Â Â Â Â Â | +------------------------------------------+ | 4e2e1a39dba84a0b5a91043bb0e4dbef23970837 | +------------------------------------------+ 1 row in set (0.00 sec)
We can know the length with the help of character_length() function.
mysql> Â SELECT CHARACTER_LENGTH(SHA1('This is a hashed password'));
The following is the output.
+-----------------------------------------------------+ | CHARACTER_LENGTH(SHA1('This is a hashed password')) | +-----------------------------------------------------+ | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 40 | +-----------------------------------------------------+ 1 row in set (0.00 sec)
Advertisements