aboutsummaryrefslogtreecommitdiff
path: root/pw_rand.c
blob: 5c9cd4ff7e284aa354f1cee3ae4ba6b4580e09da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * pw_rand.c --- generate completely random (and hard to remember)
 * 	passwords
 *
 * Copyright (C) 2001,2002 by Theodore Ts'o
 * 
 * This file may be distributed under the terms of the GNU Public
 * License.
 */

#include <string.h>
#include "pwgen.h"

#define PW_CHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

void pw_rand(char *buf, int size, int pw_flags)
{
	char	ch, *chars = PW_CHARS;
	int	i = 0, len;

	len = strlen(chars);
	while (i < size) {
		ch = chars[pw_random_number(len)];
		buf[i++] = ch;
	}
	buf[size] = 0;
	return;
}