-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPassProtector.c
62 lines (51 loc) · 1005 Bytes
/
PassProtector.c
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
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
// Define Constant KeyWords
#define ENTER 13
#define TAB 9
#define BKSP 8
//Function protoType
void password(void);
void main(){
password();
getch();
}
void password(){
char pwd[255];
char code[255] = {"Alkaison"};
int i = 0;
char ch;
system("cls");
printf("Enter your password. Hit ENTER to confirm. \n");
printf("Password:");
while(1)
{
ch = getch(); // get key
fflush(stdin); // clears the input buffer in console
if(ch == ENTER || ch == TAB)
{
pwd[i] = '\0';
break;
}
else if(ch == BKSP)
{
if(i > 0)
{
i--;
printf("\b \b"); // for backspace
}
}
else
{
pwd[i++] = ch;
printf("* \b"); // to replace password character with *
}
}
// verifies the password
if(strcmp(code, pwd) == 0)
printf("\nCorrect Password! \n");
else
printf("\nInvaild Password! \n");
}