** md5 patch by W. Campbell <wcampbel@botbay.net>
** Modernization, getopt, etc for the Hybrid IRCD team
** by W. Campbell
-**
-** /dev/random for salt generation added by
+**
+** /dev/random for salt generation added by
** Aaron Sethman <androsyn@ratbox.org>
**
** $Id: mkpasswd.c 26439 2009-02-01 15:27:24Z jilles $
static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
/* 0 .. 63, ascii - 64 */
-extern char *optarg;
-
-
#ifdef __MINGW32__
#include <conio.h>
#ifdef PASS_MAX
int c;
int i = 0;
- memset(getpassbuf, sizeof(getpassbuf), 0);
+ memset(getpassbuf, 0, sizeof(getpassbuf));
fputs(prompt, stderr);
for(;;)
{
int c;
char *saltpara = NULL;
char *salt;
+ char *hashed;
int flag = 0;
int length = 0; /* Not Set */
int rounds = 0; /* Not set, since extended DES needs 25 and blowfish needs
}
}
- if(flag & FLAG_BLOWFISH)
+ if(flag & FLAG_MD5)
+ {
+ if(length == 0)
+ length = 8;
+ if(flag & FLAG_SALT)
+ salt = make_md5_salt_para(saltpara);
+ else
+ salt = make_md5_salt(length);
+ }
+ else if(flag & FLAG_BLOWFISH)
{
if(length == 0)
length = 22;
else
salt = make_sha256_salt(length);
}
- else if(flag & FLAG_SHA512)
- {
- if(length == 0)
- length = 16;
- if(flag & FLAG_SALT)
- salt = make_sha512_salt_para(saltpara);
- else
- salt = make_sha512_salt(length);
- }
else if(flag & FLAG_EXT)
{
/* XXX - rounds needs to be done */
else
{
if(length == 0)
- length = 8;
+ length = 16;
if(flag & FLAG_SALT)
- salt = make_md5_salt_para(saltpara);
+ salt = make_sha512_salt_para(saltpara);
else
- salt = make_md5_salt(length);
+ salt = make_sha512_salt(length);
}
if(flag & FLAG_PASS)
{
if(!plaintext)
- printf("Please enter a valid password\n");
+ {
+ fprintf(stderr, "Please enter a valid password\n");
+ return 1;
+ }
+
+ hashed = rb_crypt(plaintext, salt);
}
else
{
- plaintext = getpass("plaintext: ");
+ hashed = strdup(rb_crypt(getpass("plaintext: "), salt));
+ plaintext = getpass("again: ");
+
+ if (strcmp(rb_crypt(plaintext, salt), hashed) != 0)
+ {
+ fprintf(stderr, "Passwords do not match\n");
+ return 1;
+ }
}
- printf("%s\n", rb_crypt(plaintext, salt));
+ printf("%s\n", hashed);
return 0;
}
char tbuf[3];
if(length > 22)
{
- printf("BlowFish salt length too long\n");
+ printf("Blowfish salt length too long\n");
exit(0);
}
sprintf(tbuf, "%02d", rounds);
printf("-y Generate a SHA512 password\n");
printf("-m Generate an MD5 password\n");
printf("-d Generate a DES password\n");
- printf("-b Generate a BlowFish password\n");
+ printf("-b Generate a Blowfish password\n");
printf("-e Generate an Extended DES password\n");
- printf("-l Specify a length for a random MD5 or BlowFish salt\n");
- printf("-r Specify a number of rounds for a BlowFish or Extended DES password\n");
- printf(" BlowFish: default 4, no more than 6 recommended\n");
+ printf("-l Specify a length for a random MD5 or Blowfish salt\n");
+ printf("-r Specify a number of rounds for a Blowfish or Extended DES password\n");
+ printf(" Blowfish: default 4, no more than 6 recommended\n");
printf(" Extended DES: default 25\n");
printf("-s Specify a salt, 2 alphanumeric characters for DES, up to 16 for MD5,\n");
- printf(" up to 22 for BlowFish, and 4 for Extended DES\n");
+ printf(" up to 22 for Blowfish, and 4 for Extended DES\n");
printf("-p Specify a plaintext password to use\n");
printf("Example: mkpasswd -m -s 3dr -p test\n");
exit(0);
printf("Standard DES: mkpasswd [-d] [-s salt] [-p plaintext]\n");
printf("Extended DES: mkpasswd -e [-r rounds] [-s salt] [-p plaintext]\n");
printf(" MD5: mkpasswd -m [-l saltlength] [-s salt] [-p plaintext]\n");
- printf(" BlowFish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
+ printf(" Blowfish: mkpasswd -b [-r rounds] [-l saltlength] [-s salt]\n");
printf(" [-p plaintext]\n");
printf("Use -h for full usage\n");
exit(0);