-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhash_generator.c
56 lines (43 loc) · 906 Bytes
/
hash_generator.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
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <crypt.h>
#include <ctype.h>
bool valid_password(char* pass, int size)
{
int n = strlen(pass);
if (!(n >= 0 && n <= size))
{
return false;
}
for (int i = 0; i < n; i++)
{
if(!isalnum(pass[i]))
{
return false;
}
}
return true;
}
int main(int argc, string argv[])
{
if (argc != 1)
{
printf("Usage: ./des\n");
return 1;
}
char* password;
do {
password = get_string("Enter password: ");
}
while(!valid_password(password, 6));
char* salt;
do {
salt = get_string("Enter salt: ");
}
while(!valid_password(salt, 2));
char* hash = crypt(password, salt);
printf("password is: %s\n", password);
printf("salt is: %s\n", salt);
printf("hashed password is: %s\n", hash);
}