-
Notifications
You must be signed in to change notification settings - Fork 0
/
regs.c
61 lines (39 loc) · 1.22 KB
/
regs.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <crypt.h>
char* getpass();
int signup(){
int flag=0;
char salt[2];
const char *salt_chars = "abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
char username[BUFSIZ], password1[BUFSIZ],
password2[BUFSIZ], *buf;
char filename[]="psss";
FILE *outfile;
srand(time(NULL));
salt[0] = salt_chars[rand() % 62];
salt[1] = salt_chars[rand() % 62];
printf("Username: ");
scanf("%s", username);
do {
buf = getpass("Password: ");
sprintf(password1, "%s", buf);
buf = getpass("Re-enter your password: ");
sprintf(password2, "%s", buf);
if(strcmp(password1, password2) != 0)
printf("\nPasswords do not match!\nTry again.\n\n");
} while(strcmp(password1, password2) != 0);
buf = crypt(password1, salt);
if((outfile = fopen(filename, "a+")) == NULL){
printf("\nFile error!\nAborting...\n");
} else {
fprintf(outfile, "%s:%s\n", username, buf);
flag=2;
}
fclose(outfile);
return flag;
}