-
Notifications
You must be signed in to change notification settings - Fork 0
/
passdemo.cpp
120 lines (102 loc) · 3.77 KB
/
passdemo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include<iostream>
#include<stdlib.h>
#include<cstring>
#include <conio.h>
using namespace std;
namespace Classes
{
class PasswordA
{
private :
std::string newpass,opt,q,pass;
int ctr;
public :
PasswordA()
{
ctr=0;
}
int check()
{
string pass ="";
char ch;
cout << "\n\t\tEnter Password(..Max 13 Characters..)-------------";
cout<<"\n\tWrong Password will Lead to Termination......";
ch = _getch();
while(ch != 13)
{//character 13 is enter
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "user_1234"){
return 1;
}else{
exit(0);
}
}
void change()
{
char opt,q;
system("cls");
cout<<"Are you sure you want to change the password ?(y|n) : \t " ;
cin>>opt;
if(opt=='Y'||opt=='y')
{
cout<<"Enter old password \n";
qh = _getch();
while(qh != 13)
{//character 13 is enter
q.push_back(qh);
cout << '*';
qh=_getch();
}
}
if(q==pass)
{
cout<<"Enter new password and password length shouldn't be greater than 13 characters: \n";
ph = _getch();
while(ph != 13)
{//character 13 is enter
newpass.push_back(ph);
cout << '*';
ph = _getch();
}
if(newpass.length()!=13)
{
ctr++;
cout<<"You have violated the criteria of password length\n Re-enter the new password";
if(ctr>5)
{
cout<<"You have enterd the password incorrect 5 time \n Change Aborted \n";
exit(0);
}
else
change();
}
else
{
pass=newpass;
system("cls");
cout<<"\n Password Changed succesfully";
}
}
else
{
system("cls");
cout<<"You haven't entered the old password correctly.Retry.... \n";
ctr++;
if(ctr>5)
{
cout<<"You have enterd the old password incorrectly 5 times \n Change Aborted \n";
exit(0);
}
else
change();
}
}
else
exit(0);
}
}
};
}