Skip to main content

Problem Statement

A software company is launching a secure employee portal where employees can access confidential company information. To protect user accounts from unauthorized access, the company has defined the following password policy:
  • Password length must be between 8 and 15 characters.
  • Password must contain at least one uppercase letter (A–Z).
  • Password must contain at least one special character (such as @, #, $, %, &, *, etc.).
If the password satisfies all the above conditions, it should be accepted; otherwise, the system should display an error message.

Solution

#include <stdio.h>

int main() {
    char password[50];
    int i, length = 0, uppercase = 0, special = 0;

    printf("Enter Password: ");
    scanf("%s", password);

    for(i = 0; password[i] != '\0'; i++) {
        length++;
    }

    for(i = 0; password[i] != '\0'; i++) {
        if(password[i] >= 'A' && password[i] <= 'Z')
            uppercase = 1;

        if(password[i] == '@' || password[i] == '#' ||
           password[i] == '$' || password[i] == '%' ||
           password[i] == '&' || password[i] == '*')
            special = 1;
    }

    if(length >= 8 && length <= 15 && uppercase == 1 && special == 1)
        printf("Password Accepted.");
    else
        printf("Invalid Password!");

    return 0;
}

Input

Vishal@123

Output

Password Accepted.