Operating System - HP-UX
1834101 Members
2869 Online
110063 Solutions
New Discussion

Encrypting a long password from command line

 
SOLVED
Go to solution
exec22
Occasional Advisor

Encrypting a long password from command line

I have searched the forums for this but could not figure out how to get an encrypted password for passwords of longer than 8 characters, to be used on trusted systems

For 8 characters long passwords, I can use

echo "abcd1234" | /usr/lib/makekey

and it works fine but due to my company regulations, the password I am trying to make should be at least 15 characters or more.

I have found Bill Hassel's c program below

#include
#include

/* 1st param is the desired password */
/* A random seed (2 chars) will be */
/* automatically chosen. */
/* For good passwords: */
/* Use random chars, mixed apha- */
/* numerics and MiXeD CaSe for */
/* better protection. */

main(argc, argv)
int argc;
char *argv[];
{
char salt[3];
char *EncryptedPasswd;
int CheckRand;
int Fixup;
int SeedChar;

printf("\nUsage: %s \n",argv[0]);

/* Generate a random starting point for seed charcaters */

srand(time(NULL));
for ( SeedChar = 0; SeedChar <= 1; SeedChar++)
{
CheckRand = 46 + rand() % 76; /* random from 46 to 122 */
Fixup = 7 + rand() % 13; /* random from 7 to 20 */
salt[SeedChar] = toascii(((CheckRand >= 58 && CheckRand <= 64)
|| (CheckRand >= 91 && CheckRand <= 96)
? CheckRand + Fixup : CheckRand));
}

EncryptedPasswd=crypt(argv[1], salt);
printf("\nRequested pw= %s, Seed= %s, encrypted pw= %s\n",
argv[1], salt, EncryptedPasswd);
}


and hoping that I could substitue crypt with bigcrypt to accomplish this but it was a bust. Since I am not a c programmer, I did not know what I was doing, so failure to compile was not a heartbreak.

Can anybody suggest me how to crypt a 15 or more cleartext password on the command line ?

Thanks.
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Encrypting a long password from command line

You were close. Essentially you were missing two header files and the correct library to link with:

1) Download the attached adaptation of Bill's program, pw.c, to your PC.

2) Transfer pw.c from your PC to a UNIX box using an FTP ASCII put.

3) Compile/link like this:
cc pw.c -lsec -o pw

4) Execute like this:
PWHASH=$(pw "MickeyMouse99!")
echo "Hash = \"${PWHASH}\""

I modified it to simply output the password hash output of bigcrypt rather than displaying the plaintext and salt also.


NOTE: Real UNIX guys (and gals) know at least some C.

If it ain't broke, I can fix that.