-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_acc.cpp
136 lines (119 loc) · 3.16 KB
/
create_acc.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//Returns 1 on Unsucceefull Execution
//Returns 0 on Succeefull Execution
//Used to Create an account for an User and appends that to user_list.dat file
//Copyright(2010) - Steve Robinson
#include <iostream>
#include "definitions.h"
#include <conio.h>
#include <iomanip>
using namespace std;
void encrypt (char e[] )
{
for( int i=0; e[i] != '\0'; ++i ) ++e[i];
} // encrypt
//decrypt data
void decrypt( char * ePtr ) {
for( ; * ePtr != '\0'; ++ ePtr ) --(* ePtr);
}
int create_user()
{
system("cls");
cout<<"\n----------------------------------------------\n"<<"Please Enter the Details for the New User..."<<"\n----------------------------------------------\n";
cout<<endl<<endl;
user_details tmpuser;
cout<<"\n\nUser Name: ";
fflush(stdin);
gets(tmpuser.usr_name);
fflush(stdin);
cout<<"\n\nLogin Name: ";
cin>>tmpuser.login_name;
//Masking Code for Password
int ch;
char pword1[10],pword2[10];
int i;
getpass:
cout<<"\n\nEnter Password (0 to 8 Characters): ";
i=0;
while((ch=getch())!=EOF&&ch!='\n'&&ch!='\r'&&i<10)
{
if(ch=='\b')
{
cout<<'\b';
i--;
}
else
{
pword1[i++]=ch;
cout<<'*';
}
}
pword1[i]='\0';
fflush (stdin);
cout<<"\nRe-Enter Password: ";
i=0;
while((ch=getch())!=EOF&&ch!='\n'&&ch!='\r'&&i<10)
{
if(ch=='\b')
{
cout<<'\b';
i--;
}
else
{
pword2[i++]=ch;
cout<<'*';
}
}
pword2[i]='\0';
if(strcmp(pword1,pword2)!=0)
{
cout<<"\n\nEntered Passwords donot Match!\n\n";
goto getpass;
}
//encryption and storing in object
encrypt(pword1);
strcpy(tmpuser.password,pword1);
int len;
len=strlen(tmpuser.login_name);
strcpy(tmpuser.file_name,tmpuser.login_name);
strcat(tmpuser.file_name,".dat");
tmpuser.entries=0;
cout<<"\n\n----------------------------------------------\nNew User Account Successfully Created!\n----------------------------------------------\n";
cout<<endl<<endl;
ofstream fwrite("user_list.dat",ios::app|ios::binary);
if(fwrite.is_open())
{
fwrite.write((char *)&tmpuser,sizeof(tmpuser));
if(fwrite.fail())
{
cout<<"\n\nError: Unable to write to Disk File!";
fwrite.close();
getch();
return 1;
}
else
fwrite.close();
}
else
{
ofstream fwrite("user_list.dat",ios::out|ios::binary|ios::trunc);
if(fwrite.is_open())
{
fwrite.write((char *)&tmpuser,sizeof(tmpuser));
if(fwrite.fail())
{
cout<<"\n\nError: Unable to write to disk file!\n\n";
fwrite.close();
getch();
return 1;
}
else
{
fwrite.close();
}
}
}
cout<<"\nReturning to root.";
getch();
return 0;
}