aboutsummaryrefslogtreecommitdiff
path: root/pw_rand.c
blob: e49ff761f5919ad555dae6de31abd66c085a2750 (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
29
30
31
32
/*
 * 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 FIRST_CHAR '!'
#define LAST_CHAR '~'

static char bad_chars[] = "'\\\"!@#$%^&*()+=_-{}[]<>`~?:;,/.|";

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

	while (i < size) {
		ch = pw_random_number(LAST_CHAR - FIRST_CHAR) + FIRST_CHAR;
		if (strchr(bad_chars, ch))
			continue;
		buf[i++] = ch;
	}
	buf[size] = 0;
	return;
}