-
Notifications
You must be signed in to change notification settings - Fork 0
/
signin.c
76 lines (76 loc) · 1.9 KB
/
signin.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "reddit.h"
/**
Function Name: login_user
Input Params:NIL
Return Type: void
Description: username ,pass word is taken from the user and checks if the username already exists ,if exists return failure
else accepted,password is encrypted ,all the information is written in the file
**/
int login_user()
{
main_user_holder = (USER_HOLDER *)malloc(sizeof(USER_HOLDER));
main_user_holder->user_content = (USER *)malloc(sizeof(USER));
printf("\n\xB2\xB2\xB2\xB2");
blue();
printf(" Login ");
reset();
printf("\xB2\xB2\xB2\xB2\n");
char entered_username[31];
char temp_char;
char pwd[31];
int i = 0;
int status = 0;
printf("Username : ");
scanf("%s", entered_username);
printf("Password : ");
do
{
temp_char = getch();
if (temp_char != '\b')
{
pwd[i] = temp_char;
if (temp_char != '\r')
printf("*");
i++;
}
else
{
if (i != 0)
{
i--;
printf("\b \b");
}
continue;
}
} while (pwd[i - 1] != '\r');
pwd[i - 1] = '\0';
status = auth_user(entered_username, pwd);
if (status == SUCCESS)
{
strcpy(main_user_holder->user_content->username, entered_username);
// print_success("Login Successful! You will be redirected");
timeout(2);
screen_reset();
is_loggedin = 1;
return SUCCESS;
}
else
return FAILURE;
}
/**
Function Name: add_username_file
Input Params:char username_r[18]
Return Type: void
Description: a file to store the information of the user is created
**/
void add_username_file(char username_r[18])
{
FILE *fp = fopen("files/auth/loggedin.rdt", "w+");
if (fp == NULL)
{
printf("Error opening file!");
return;
}
fprintf(fp, "%s", username_r);
fclose(fp);
}