~ubuntu-branches/debian/sid/pwgen/sid

« back to all changes in this revision

Viewing changes to pw_rand.c

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Renardias
  • Date: 2001-12-06 17:38:58 UTC
  • Revision ID: james.westby@ubuntu.com-20011206173858-jf0wwxjtrm7e68hg
Tags: upstream-2.01
ImportĀ upstreamĀ versionĀ 2.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * pw_rand.c --- generate completely random (and hard to remember)
 
3
 *      passwords
 
4
 *
 
5
 * Copyright (C) 2001 by Theodore Ts'o
 
6
 * 
 
7
 * This file may be distributed under the terms of the GNU Public
 
8
 * License.
 
9
 */
 
10
 
 
11
#include "pwgen.h"
 
12
 
 
13
#define FIRST_CHAR '!'
 
14
#define LAST_CHAR '~'
 
15
 
 
16
static char bad_chars[] = "'\\\"";
 
17
 
 
18
void pw_rand(char *buf, int size, int pw_flags)
 
19
{
 
20
        char    ch;
 
21
        int     i = 0;
 
22
 
 
23
        while (i < size) {
 
24
                ch = pw_random_number(LAST_CHAR - FIRST_CHAR) + FIRST_CHAR;
 
25
                if (strchr(bad_chars, ch))
 
26
                        continue;
 
27
                buf[i++] = ch;
 
28
        }
 
29
        buf[size] = 0;
 
30
        return;
 
31
}