1824937 Members
3967 Online
109678 Solutions
New Discussion юеВ

Crypt

 
SOLVED
Go to solution
Mauro Gatti
Valued Contributor

Crypt

Hi all,
I'd like to create a little C program that use the same crypt algorithm of passwd command.
The program must accept one argument that is the word to crypt and must return the encrypted word.

Do You could give me an Idea to do it?
Ubi maior, minor cessat!
4 REPLIES 4
Bill McNAMARA_1
Honored Contributor

Re: Crypt

man crypt ?

Later,
Bill
It works for me (tm)
Mauro Gatti
Valued Contributor

Re: Crypt

I've already tried but crypt command do not use the same algorythm of passwd.
I've found in man 3c crypt the crypt() function but I'd like to see some example to understand how use it.
Ubi maior, minor cessat!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Crypt

It's actually easy:

1) Extract the 1st two characters of the existing password (old_passwd) hash - this is the 'salt'.

2) char *passwd2 = crypt(plaintext,salt);

3) if (strcmp(old_passwd,passwd2) == 0)
{
printf("Password okay\n");
}

When choosing a new password, you are advised to create a new salt value. The attached snippet will prove useful.


If it ain't broke, I can fix that.
Jack Tan
Occasional Advisor

Re: Crypt

Be aware that passwords longer than 8 characters should be encrypted on trusted HP-UX using bigcrypt() instead of crypt(). On other platforms, other functions are used besides bigcrypt(), such as dispcrypt() on Tru64.

If you need a cross-platform solution, I'd suggest looking at the source code to sudo (http://www.courtesan.com/sudo/) and wu-ftpd (http://www.wu-ftpd.org/).