Created
December 14, 2014 02:43
-
-
Save Sebbyastian/a692516e8392b214b3e9 to your computer and use it in GitHub Desktop.
BR password challenge (too easy, m8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) { | |
unsigned int length = 0; | |
enum { empty = 0, | |
lower_alpha = 1, | |
upper_alpha = 2, | |
decim_digit = 4, | |
punctuation = 8 } criteria = empty; | |
puts("Please enter a password and I'll judge its security..."); | |
for (;;) { | |
int c = getchar(); | |
if (c < 0 || c == '\n') { | |
break; | |
} | |
criteria |= lower_alpha * (islower(c) > 0); | |
criteria |= upper_alpha * (isupper(c) > 0); | |
criteria |= decim_digit * (isdigit(c) > 0); | |
criteria |= punctuation * (ispunct(c) > 0); | |
length = length == 8 | |
? length | |
: length + 1; | |
} | |
# define PREFIX "Your password must contain at least " | |
puts((criteria & lower_alpha) == 0 ? PREFIX "one lower alpha character" | |
: (criteria & upper_alpha) == 0 ? PREFIX "one upper alpha character" | |
: (criteria & decim_digit) == 0 ? PREFIX "one decimal digit character" | |
: (criteria & punctuation) == 0 ? PREFIX "one punctuation character" | |
: length < 8 ? PREFIX "eight characters" | |
: "Your password seems secure to me!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment