Re: problem generating passwords upro wrote:
>Hi there!
>
>
>I have been generating passwords for users automatically with the
>following method:
>
>/usr/bin/mkpasswd -s 0 -v username
>
>I'm the sysadmin on a Slack 10.0 system.
>
>The passwords are generated (you have to wait some seconds), and there
>is actually something written to the /etc/shadow file. But they won't
>work!
>
>Can someone please help me, I have no idea why they should not work!
>
>Thank You In Advance,
>
>
Try the following.
It will generate a standard Unix/Linux password that you can copy/paste
into shadow (or group). I use this for generating passwords for CVS.
Compile it with
cc -o cvspas cvspas.c -lcrypt
Have fun.
#ident "$Id: cvspas.c,v 1.1 2004/11/08 17:51:40 trona Exp $"
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <time.h>
#include <unistd.h>
extern char *crypt (const char *, const char *);
void main (int argc, char *argv [])
{
char salt [3];
char *passwd, *encryptedpw;
char *user;
int i;
/* seed the random number generator */
srand ((int) time ((unsigned int) NULL));
/*
* we need two random numbers in the range
* >= 65 <= 90 or >= 97 <= 122 (that's A - Z
* or a - z inclusive) for the salt characters
*/
while ((i = rand()) < 65 ||
i > 90 && i < 97 ||
i > 122)
;
salt [0] = i;
while ((i = rand()) < 65 ||
i > 90 && i < 97 ||
i > 122)
;
salt [1] = i;
salt [2] = '\0';
/* find out who we are */
if ((user = getenv ("USER")) == (char *) NULL) {
(void) fprintf (stderr,
"%s:\tunable to determine user id\n",
argv [0]);
exit (EXIT_FAILURE);
}
/* ask for the password */
passwd = getpass ("Password to encrypt: ");
/* crypt() only looks at the first two characters of salt */
encryptedpw = crypt (passwd, salt);
(void) fprintf (stdout, "%s:%s\n", user, encryptedpw);
exit (EXIT_SUCCESS);
} |