summaryrefslogtreecommitdiff
path: root/usr.bin/passwd/pwd_gensalt.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>1997-03-27 00:05:42 +0000
committerNiels Provos <provos@cvs.openbsd.org>1997-03-27 00:05:42 +0000
commitf0b12dfc6b64611b09f16b6a9caf9f0acfdf181c (patch)
treebfd0d5abc83ec2741317453a44f9b8bff2e6025f /usr.bin/passwd/pwd_gensalt.c
parent3a3f0c846e7b1b65cf50ee8b54caacf304488497 (diff)
support for md5 passwords
Diffstat (limited to 'usr.bin/passwd/pwd_gensalt.c')
-rw-r--r--usr.bin/passwd/pwd_gensalt.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/usr.bin/passwd/pwd_gensalt.c b/usr.bin/passwd/pwd_gensalt.c
index 80dff3ba1ab..2c7ce64c2c0 100644
--- a/usr.bin/passwd/pwd_gensalt.c
+++ b/usr.bin/passwd/pwd_gensalt.c
@@ -67,26 +67,32 @@ pwd_gensalt(salt, max, pwd, type)
(void) srandom((int) time((time_t *) NULL));
to64(&salt[0], random(), 2);
salt[2] = '\0';
- } else
- if (!strcmp(now, "newsalt")) {
- if( max < 10 )
- return 0;
- (void) srandom((int) time((time_t *) NULL));
- salt[0] = _PASSWORD_EFMT1;
- to64(&salt[1], (long) (29 * 25), 4);
- to64(&salt[5], random(), 4);
- salt[9] = '\0';
- } else
- if (!strcmp(now, "blowfish")) {
- int rounds = atoi(next);
- if (rounds < 4)
- rounds = 4;
- strncpy(salt, bcrypt_gensalt(rounds), max - 1);
- salt[max - 1] = 0;
- } else {
- strcpy(salt, ":");
- warnx("Unkown option %s.", now);
- }
+ } else if (!strcmp(now, "newsalt")) {
+ if( max < 10 )
+ return 0;
+ (void) srandom((int) time((time_t *) NULL));
+ salt[0] = _PASSWORD_EFMT1;
+ to64(&salt[1], (long) (29 * 25), 4);
+ to64(&salt[5], random(), 4);
+ salt[9] = '\0';
+ } else if (!strcmp(now, "md5")) {
+ if( max < 13 ) /* $1$8salt$\0 */
+ return 0;
+ strcpy(salt, "$1$");
+ (void) srandom((int) time((time_t *) NULL));
+ to64(&salt[3], random(), 4);
+ to64(&salt[7], random(), 4);
+ strcpy(&salt[11], "$");
+ } else if (!strcmp(now, "blowfish")) {
+ int rounds = atoi(next);
+ if (rounds < 4)
+ rounds = 4;
+ strncpy(salt, bcrypt_gensalt(rounds), max - 1);
+ salt[max - 1] = 0;
+ } else {
+ strcpy(salt, ":");
+ warnx("Unkown option %s.", now);
+ }
return 1;
}