Friday, 16 May 2014

Secured and confirm Password

Note: This program has been checked using dev-c++  and code::blocks compiler.


#include<conio.h>
#include<iostream>
#include<string.h>
#include<windows.h>
using namespace std;

int main()
{
enter:
int i=0,flag=0,flag1=0,flag2=0,flag3=0,c=0,size=0,size1=0,t=0,t1=0,fail=0,null=0;
char p[15],a,p1[15];

cout<<"\nyour paasword must contain atleast one uppercase, one lowercase, one numeric value and one special character\n";
cout<<"enter password:  ";
while(a!=13)
{
a=getch();
if(a==13)
break;
cout<<"*";
if(a!=8)
{
p[i]=a;

    size=i++;
    }
    p[i]='\0';

if(a==8)
    {
    system("cls");
    t++;
    i--;
    p[i+1]='\0';
    for(int i=0;i<=size-t;i++)
    {
    p[i];
    cout<<"*";
    }
    }

    }
   
    for(int i=0;i<strlen(p);i++)
{
if(p[i]>='A' && p[i]<='Z')
{
flag++;
break;
}
}
for(int i=0;i<strlen(p);i++)
{ if(p[i]>='a' && p[i]<='z')
{ flag1++;
break;} }

for(int i=0;i<strlen(p);i++)
{ if(p[i]>='0' && p[i]<='9')
{ flag2++;
break;} }


for(int i=0;i<strlen(p);i++)
{ if(p[i]==33 || p[i]==126 || p[i]==64 || p[i]==35 ||p[i]==36 || p[i]==37||p[i]==94||p[i]==38 ||p[i]==40||p[i]==41||p[i]==42||p[i]==95||p[i]==43)
{ flag3++;
break;
}
}
for(int i=0;i<strlen(p);i++)
{ if(p[i]=='\0')
{ null++;
break;} }

if(flag==0||flag3==0||flag1==0||flag2==0)
{
cout<<"\nyour paasword must contain atleast one uppercase, one lowercase, one numeric value and one special character \n";
cout<<" press 'y' to enter password again :";
a=getch();
if(a=='y' || a=='Y')
{
goto enter;
}
else {goto enter; }
}
 
  again:
  {
 
  i=0,size1=0,t1=0;
  cout<<"\n enter again to confirm your password :";
  char b1;
 
  while((b1=getch())!=13)
  {
if(b1==13)
break;
cout<<"*";
if(b1!=8)
{
p1[i]=b1;
    size1=i++;
}
p1[i]='\0';

  if(b1==8)
    {
    system("cls");
    t++;
    i--;
    p1[i+1]='\0';
    for(int i=0;i<=size-t;i++)
    {
    p1[i];
    cout<<"*";
    }
    }
   }
   if((strlen(p))!=(strlen(p1)))
  {
  cout<<"\n wrong password: ";
  goto again;}

else

   if((strlen(p))==(strlen(p1)))
  {
  for(int i=0;i<strlen(p);i++)
    {
  if(!(p[i]==p1[i]))
    {
    cout<<"\n wrong password: ";
    goto again;
    }
    }
    cout<<"\n ........congrats.... \n password accepted :";
    }

}
getch();
return 0;
}

No comments:

Post a Comment