Tuesday 13 January 2015

Program to Validate password or check password using C program

#include<stdio.h>
#include<stdlib.h>
void check(char a[]);
main()
{
    char a[100];
    printf("Enter your password that should satisfy the following criteria\n1. password should contain atleast one capital letter\n2. should have one digit from(o-9)\n3. atleast one special charecter($,*,#,&)\n4. length should be atleast 6\n");
    scanf("%s",a);
    check(a);


}
void check(char a[])
{
    char c;
    int len,i,flag1=0,flag2=0,flag3=0,flag4=0;
    len=strlen(a);
    if(len<6)
    flag1=1;
    else
    {
        for(i=0;i<len;i++)
        if((a[i]>=48&&a[i]<=58))
        {
            flag2=0;

            break;
        }
        else
        flag2=1;

        for(i=0;i<len;i++)
        if((a[i]>=65&&a[i]<=90))
        {
            flag3=0;

            break;
        }
        else
        flag3=1;

        for(i=0;i<len;i++)
        if(a[i]=='#'||a[i]=='$'||a[i]=='*'||a[i]=='&')
        {
            flag4=0;

            break;
        }
        else
        flag4=1;


    }
    if(flag1==1||flag2==1||flag3==1||flag4==1)
    printf("\nWrong password\n");
    else
    printf("your password is successfully created\n");


    return;
}



Enter your password that should satisfy the following criteria
1. password should contain atleast one capital letter
2. should have one digit from(o-9)
3. atleast one special charecter($,*,#,&)
4. length should be atleast 6
Shahul12$
your password is successfully created

Process returned 0 (0x0)   execution time : 17.182 s
Press any key to continue.

5 comments:

  1. it works, but can you explain how it works sir?

    ReplyDelete
  2. Nice post.I like the program.it works.Have a look on custom software development company,if you want any software solutions.we bring to you the BEST solutions at nominal rates.

    ReplyDelete
  3. #include
    int main()
    {
    char pass[31];
    printf("Enter a password(Not more than 30 characters): \n");
    scanf(" %s", pass);
    if(isalpha(pass))
    {
    if(isalnum(pass)){
    if(isupper(pass)){
    if(islower(pass)){
    if(isascii(pass)){

    }
    }
    }
    }
    printf("You have a powerful password!");
    }
    else{
    printf("Hey, your password sucks!");
    }
    }

    ReplyDelete
  4. It doesn't work at all, it only prints the else statement

    ReplyDelete