In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces in Linux how to use MD5 to achieve user authentication related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will have something to gain after reading this article on how to use MD5 in Linux to achieve user authentication, let's take a look.
Using the md5 function in openssl, which returns 16 bytes of data of type unsigned char, each byte in the range of 0,0255. set the
It is formatted in hexadecimal, which is 32-bit md5 encoding. Note: a byte is 8 bits, which is exactly 2-bit hexadecimal.
Use the user name of the login client to get the salt value and the encrypted password from the redis database, and then encrypt the password of the login client through salt.
Compare passwords in the redis database. If the same is the same, the verification passes, otherwise the verification fails.
The password in the redis database is stored in password:salt format
The user authentication algorithm is as follows:
Int user_authenticate (char * username, char * password)
{
Char * salt_pw, * salt, * pw
Char buf [40]
Char tmp [3] = {'\ 0'}, md5_str [33] = {'\ 0'}
Unsigned char md [16]
Int i
/ / get_salt_pw calls redis database to get password:salt
Salt_pw = get_salt_pw (db, username)
Pw = strtok (salt_pw, ":")
If (! pw) {
Return 0
}
Salt = strtok (null, ":")
If (! salt) {
Return 0
}
Strcpy (buf, password)
Strcat (buf, salt)
Md5 ((const unsigned char*) buf, strlen (buf), md)
/ / transform to md5 string
For (I = 0; I < 16; iTunes +) {
Sprintf (tmp, "x", md [I])
Strcat (md5_str, tmp)
}
/ / compare encode password using md5
If (strcmp ((char*) md5_str, pw)) {
Return 0
}
Return 1
}
Note the use of the strtok function and the process of converting a 16-byte unsigned char into a 32-bit hexadecimal number.
This is the end of the article on "how to use MD5 to achieve user authentication in Linux". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use MD5 to achieve user authentication in Linux". If you want to learn more knowledge, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.