SUMMARY: encryp password

From: Ing. Silvia Beltr\an S\anchez (silvia@snsp.gob.mx)
Date: Mon Nov 23 1998 - 17:01:23 CST


Thanks for all the responses !!!

The question was:
"I want to have a script that automatically adds users to the passwd
file. My script takes the arguments and creates a row according to the
format of the /etc/passwd, but I don't know how can I encrypt the
password.
I am using Solaris 2.6, I had a C program (rpass.c) that encrypt a word
like a password but it just works in solaris 2.5.1."

I used the response number 8 and it works fine :-), but all the messages
were great ideas.
Regards.
Silvia
-----------------------------------------------------------------
This message include 9 replies.
-------------------------------------------------------------------
1. Harvey Wamboldt <harvey@iotek.ns.ca>
/* Reverse with easy salt mkpasswd.c */
#include <stdio.h>
#include <string.h>
main(argc, argv)
  int argc;

  char *argv[];
{
  char line[512], salt[3];

  int i, l;

  salt[2] = '\0';
  /* No parameters there read from standard input */
  if (argc == 1) {
    while (gets(line) != NULL) {
      l = strlen(line);
      if (l > 2) {
        salt[0] = line[0];
        salt[1] = line[1];
        printf("%s\n", crypt(line + 2, salt));
      } else
        fprintf(stderr, "Too short [%i] \"%s\"\n", l, line);
    }
  } else {
    for (i = 1; i < argc; i++) {
      l = strlen(argv[i]);
      if (l > 2) {
        salt[0] = argv[i][0];
        salt[1] = argv[i][1];
        printf("%s\n", crypt(argv[i] + 2, salt));
      } else {
        fprintf(stderr, "Too short [%i] \"%s\"\n", l, argv[i]);
        return (1);
      }
    }
  }
  return (0);
}
----------------------------------------------------------------------
2. Mark Neill <Mark.Neill@fanb.com>
" My preference (and what I am about to do here) would be to write the
program in Perl, or at least the crypter. Pick 1 random characters
from [a-z0-9A-Z] as the salt, then run the salt and the PW through
crypt()."
--------------------------------------------------------------------
3. "Lee Trujillo" <leet@navidec.com>
#!/usr/local/bin/perl

# This little program prompts you for a password, selects a random
# salt, and gives you the encoded result to put it in the bot's
# config file.

$chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

srand;

print "
This program takes a password and encodes it, so you can put the
encoded version on a bot-tom configuration file.

Enter password: ";
$plaintext=<>;
chop($plaintext);

if (length($plaintext)>8 || length($plaintext)<2) {
  print "Invalid length!\n";
  exit;
}

$salt=substr($chars, rand(length($chars)), 1).
      substr($chars, rand(length($chars)), 1);

print "Encoded password is: ", crypt($plaintext, $salt), "\n\n";
--------------------------------------------------
4. Nickolai Zeldovich <kolya@zepa.net>
" You can either use the 'expect' package which has a wrapper for
/usr/bin/passwd to set the password to whatever you wish, or you could
use the crypt(3) C function to encrypt passwords in your C code."
--------------------------------------------------------
5. Andy De Petter <andy@abcomp.be>
"If you have written your script in perl, you can use the
crypt($password,$salt) function... see the perl manual for more
information about it."
-------------------------------------------------------
6. mht@clark.net
"In both Evi Nemeth's Book UNIX System Administration and Aeileen
Feesch's book Essential UNIX System Administrator's Handbook, they
explain the use of the adduser script and both I think have a routine
that explains your issue. "

(Thanks, but the handbook doesn't explain the way for encript the
password :-) )
---------------------------------------------------------
7. Mark Sherman [ Y2k Consultant ]" <marksh@funb.com>

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
void mkpasswd(char *string);
int main(int argc, char *argv[])
{
char salt[]="AB";
char P[9]="fun1998";
/* mkpasswd(P); */
printf("the original passwd is %s\n",P);
printf("the encrypted passwd is %s\n",crypt(P,salt));
exit(0);
}
void mkpasswd(char *string)
{
int i = 0;
int c;
srand(getpid());
while (i < 8)
{
c = rand();
while ( c >= 123 || c <= 96 )
{
if (c > 122 )
c = c/2;
if (c < 97)
c = c*2;
}
printf("c is %i\n",c);
*string=c;
i++;
string++;
}
}
--------------------------------------------------------
8. Sean Ward <sdward@uswest.com>

#include <stdio.h>
#include <crypt.h>
main(argc,argv)
int argc;
char **argv;
{
  char *passwd;
  char *salt;
  passwd = argv[1];
  salt = argv[2];
  printf("%s\n", crypt(passwd,salt));
}

---------------------------------------------------------
9. Angel Ortiz <cherub@lava.net>

" You can use the "crypt" command. Check the man pages. Or... You can
use the htpasswd executable that is used to created passwords for
netscape hope pages..."
------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:53 CDT