Linux encryption function crypt ()

Source: Internet
Author: User
Tags crypt

/*
Use the "crypt" function to encrypt the passward of the logining user
The Declaration of the function is:
Char * crypt (const char * Key, const char * salt );
Key: The passward to encrypt
Salt: Maid ([a-zA-Z0-9./]) Here we set "salt" the first and the last character
Of the AGRU key
Return Value: contain 13 characters including the first two character is the "salt" AGRU
2006-02-18-9: 40
*/

# DEFINE _ xopen_source
# Include <unistd. h>
# Include <stdio. h>

Char * encode (const char * passward)
{
Char Salt [3];
Char * result;
Int size = strlen (passward );
Salt [0] = passward [0];
Salt [1] = passward [size-1];
Salt [2] = '/0 ';
Result = crypt (passward, salt );
Printf ("% s/n", result );
Return result;
}
Int main ()
{
Char * Key = "whhit_liyanan_computer_science ";
Char * result;
Result = encode (key );
Printf ("the result of the encrypt is: % s/n", result );
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.