Operating System - HP-UX
1748198 Members
2663 Online
108759 Solutions
New Discussion

Re: Encrypting a password

 
Vidhya B
Frequent Advisor

Encrypting a password

Is there any command in which I will be able to specify the encrypted password of a user and change the password?

 

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: Encrypting a password

Bill Hassell
Honored Contributor

Re: Encrypting a password

There is a way to create an encrypted password from HP-UX commands but it isn't simple:

typeset -L8 PW


(assign the desired password (8 characters or less) to PW. Passwords longer than 8 characters will require some programming and a look at the man page for bigcrypt(3c). Note that a standard HP-UX system (non-Trusted) will ignore characters in a password after the 8th character. A Trusted system will honor characters beyond 8 but makekey can't handle them.

The typeset -L8 will create a space filled character string for short passwords.


SALT=$( awk '
  BEGIN {
  CHARS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"
  srand()
  printf("%s%s", substr(CHARS,1 + int(rand() * 64),1), \
                 substr(CHARS,1 + int(rand() * 64),1))
  } ')
ENCRYPTED=$(echo "$PW$SALT" | tr -A " " "\000" | /usr/lbin/makekey)

The tr command changes the trailing spaces to nulls (required for makekey).
Now you can set/change the password using usermod -p like this:

/usr/sam/lbin/usermod.sam -p "$ENCRYPTED" userID



Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: Encrypting a password

Hi:

 

Here's a simple Perl script to generate an encrypted password from a plaintext one:

# cat .pwgen
#!/usr/bin/perl -l
die "One arg expected\n" unless @ARGV;

print crypt(
    $ARGV[0],
    join( '',
        ( '.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z' )[ rand 64, rand 64 ] )
);
1;

...run as:

# ./pwgen plaintext

...to produce the corresponding encrypted password.


Regards!

 

...JRF...