Skip to content

Instantly share code, notes, and snippets.

@Sebbyastian
Created December 14, 2014 02:43
Show Gist options
  • Save Sebbyastian/a692516e8392b214b3e9 to your computer and use it in GitHub Desktop.
Save Sebbyastian/a692516e8392b214b3e9 to your computer and use it in GitHub Desktop.
BR password challenge (too easy, m8)
#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