aboutsummaryrefslogtreecommitdiff
path: root/pw_rand.c
diff options
context:
space:
mode:
authorPhilipp Klaus <philipp.klaus@gmail.com>2011-06-21 17:12:21 +0200
committerPhilipp Klaus <philipp.klaus@gmail.com>2011-06-21 17:12:21 +0200
commit4535ac486ce87b6a7257a7959426138405b7ecf8 (patch)
tree2b397f1430e62032aa696dd8fe0b91fd8b6a3269 /pw_rand.c
downloadpwgen-4535ac486ce87b6a7257a7959426138405b7ecf8.zip
automatic commit for pwgen-2.0
Diffstat (limited to 'pw_rand.c')
-rw-r--r--pw_rand.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/pw_rand.c b/pw_rand.c
new file mode 100644
index 0000000..e42a656
--- /dev/null
+++ b/pw_rand.c
@@ -0,0 +1,31 @@
+/*
+ * pw_rand.c --- generate completely random (and hard to remember)
+ * passwords
+ *
+ * Copyright (C) 2001 by Theodore Ts'o
+ *
+ * This file may be distributed under the terms of the GNU Public
+ * License.
+ */
+
+#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;
+}