-
Notifications
You must be signed in to change notification settings - Fork 3
/
lab09-01.c
executable file
·85 lines (62 loc) · 1.94 KB
/
lab09-01.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
77
78
79
80
81
82
83
84
/* lab09-01.c
* =============================================================
* Name:
* Section:
* Purpose:
* =============================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MIN_PASSW_LEN 7
#define MAX_PASSW_LEN 50
/* -------------------------------------------------------
* @brief Computes the Hash. You do not need to modify this function
* @param str the string to hash
* @param length the length of the string
*/
unsigned int ELFHash(const char* str, unsigned int length) {
unsigned int hash = 0;
unsigned int x = 0;
unsigned int i = 0;
for (i = 0; i < length; ++str, ++i) {
hash = (hash << 4) + (*str);
if ((x = hash & 0xF0000000L) != 0) {
hash ^= (x >> 24);
}
hash &= ~x;
}
return hash;
}
int main(void) {
// TODO String Variables
// How large should these be to store the string and the NULL terminator?
// Should we use predefined constants?
char newPass[] = "";
char repeatPass[] = "";
int newPassLen = 0;
// Get New Password Candidate from the User
printf("enter a new password NO SPACES ");
printf("(%d to %d chars long): ", MIN_PASSW_LEN, MAX_PASSW_LEN);
// TODO scanf
// Check the Length of the New Password Candidate
// TODO Get String Length
if(newPassLen < MIN_PASSW_LEN){
printf("new password is too short - terminating\n");
exit(1);
}
// TODO Check to See if Password is Too Long
// Get the Password a Second Time
printf("enter it again: ");
// TODO Get the Password Again
// Check to See if the Entries Match
// TODO Compare String
// printf("new password accepted\n");
// printf("it will be stored as: %0x32u\n", ELFHash(newPass, newPassLen));
//}
//else {
// printf("passwords do not match - terminating\n");
// exit(1);
//}
return 0;
}