Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <stdbool.h>
- #include <string.h>
- #define MIN_PASSWORD_LENGTH 5
- int get_password_length();
- bool get_password_number();
- bool get_password_capital();
- bool get_password_sign();
- int main()
- {
- char password[10];
- char c;
- int i = 0;
- while((c = getchar()) != '\n')
- {
- password[i++] = c;
- }
- password[i] = '\0'; // Determines null by the end of the string.
- int passwordLength = get_password_length(password);
- printf("Password Length: %d\n", passwordLength);
- if(passwordLength < MIN_PASSWORD_LENGTH)
- {
- printf("Password must contain at least 5 characters!");
- return 0;
- }
- if(!get_password_number(password, passwordLength))
- {
- printf("Password must contain a number!");
- return 0;
- }
- if(!get_password_capital(password, passwordLength))
- {
- printf("Password must contain a capital letter!");
- return 0;
- }
- if(!get_password_sign(password, passwordLength))
- {
- printf("Password must contain a special sign!");
- return 0;
- }
- printf("Your password meets all of the requirements!");
- }
- int get_password_length(char* password)
- {
- int length = 0;
- char* p = password;
- while (*p != '\0')
- {
- length++;
- p++;
- }
- return length;
- }
- bool get_password_number(char* password, int passwordLength)
- {
- char* p = password;
- for(int i = 0; i < passwordLength; i++)
- {
- if(*p >= '0' && *p <= '9')
- return true;
- p++;
- }
- return false;
- }
- bool get_password_capital(char* password, int passwordLength)
- {
- char* p = password;
- for(int i = 0; i < passwordLength; i++)
- {
- if(*p >= 'A' && *p <= 'Z')
- return true;
- p++;
- }
- return false;
- }
- bool get_password_sign(char* password, int passwordLength)
- {
- char* p = password;
- for(int i = 0; i < passwordLength; i++)
- {
- if(*p >= '!' && *p <= '/' || // !"#$%&'()*+,-./
- *p >= ':' && *p <= '@' || // :;<=>?@
- *p >= '[' && *p <= '`' || // {|}~
- *p >= '{' && *p <= '~')
- return true;
- p++;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement