aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-01-14 00:24:59 +1100
committerNicholas Tay <nick@windblume.net>2022-01-14 00:24:59 +1100
commita2f5bce2bd1e462f9cd26d3278ff7dd355bf9540 (patch)
treed0768ba278972066765addf990e1387520c92a5f
parenta2d5d3b8101a674031745c1609da2644522249c2 (diff)
downloadpassgen-a2f5bce2bd1e462f9cd26d3278ff7dd355bf9540.tar.gz
passgen-a2f5bce2bd1e462f9cd26d3278ff7dd355bf9540.tar.bz2
passgen-a2f5bce2bd1e462f9cd26d3278ff7dd355bf9540.zip
Fix grammar caps generation on new grammars
-rw-r--r--passgen.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/passgen.c b/passgen.c
index 0b6631d..2ab9bf0 100644
--- a/passgen.c
+++ b/passgen.c
@@ -183,12 +183,9 @@ Compile-time options (edit `config.h` to customise!):\n\
for (int i = 0; i < grammar_size; ++i) {
char c = grammar[i];
-
- bool caps = false;
- if (c >= 'A' && c <= 'Z') {
- caps = true;
+ bool caps = c >= 'A' && c <= 'Z';
+ if (caps)
c += 'a' - 'A';
- }
struct grammar_class *class = NULL;
for (int j = 0; j < classes_n; ++j) {
@@ -204,7 +201,9 @@ Compile-time options (edit `config.h` to customise!):\n\
}
do {
- password[i] = class->letters[get_rng() % class->size] - (caps ? 'a' - 'A' : 0);
+ password[i] = class->letters[get_rng() % class->size];
+ if (caps && password[i] >= 'a' && password[i] <= 'z')
+ password[i] -= 'a' - 'A';
} while (i != 0 && password[i] == password[i - 1]);
}