-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.cpp
67 lines (50 loc) · 1.2 KB
/
11.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
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to store ID and Password & check login credentials
#include <fstream.h>
#include <conio.h>
#include <string.h>
struct db
{
char id[10];
char pass[10];
};
void main()
{
clrscr();
db user;
int found;
char userID[10], userPass[10];
fstream file("password.dbf", ios::in | ios::out);
// Input
for(int i=0; i<5; i++)
{
cout << "Enter Details:- " << endl;
cout << "User Name: ";
cin >> user.id;
cout << "Password: ";
cin >> user.pass;
file.write((char*) &user, sizeof(user));
}
cout << "Login Page!\n";
cout << "Username: ";
cin >> userID;
cout << "Password: ";
cin >> userPass;
// Checking
file.seekg(0,ios::beg);
while(file.read((char*) &user, sizeof(user)) && found != 1)
{
if(strcmpi(userID, user.id) == 0 && strcmpi(userPass,user.pass) == 0)
found = 1;
else found = 0;
}
if(found == 1)
cout << "Access Allowed!\n\n";
else cout << "Access Denied!\n\n";
file.close();
getch();
}