-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.c
124 lines (122 loc) · 2.08 KB
/
validate.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
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
int validate_text(char string[20], int length)
{
int i;
for(i=0;i<length;i++)
{
if( isalpha(string[i]) )
{
continue;
}
else
{
return 0;
}
}
return 1;
}
int validate_username(char string[20], int length)
{
int i=1;
if( isalpha(string[0]) )
{
if( string[i] =='\0' )
{
printf("\nInvalid Username: Username must contain @ character");
return 0;
}
for( i=1 ; string[i] != '\0' ; )
{
if( string[i] == '@' )
{
i++;
break;
}
else
i++;
if( string[i+1] == '\0' )
{
printf("\nInvalid Username: Username must contain @ character");
return 0;
}
}
if( string[i] == '.' )
{
printf("\nInvalid Username: Alphabets must succeed @");
return 0;
}
while( string[i] != '.' )
{
if( isalpha(string[i]) )
{
i++;
continue;
}
if( string[i] == '\0' )
{
printf("\nInvalid Username: Username must contain . character");
return 0;
}
else
{
printf("\nInvalid Username: Only alphabets are permitted succeeding @");
return 0;
}
}
i++;
while( string[i] !='\0')
{
if( isalpha(string[i]) )
{
i++;
continue;
}
else
{
printf("\nInvalid Username: Only alphabets are permitted succeeding .");
return 0;
}
}
return 1;
}
printf("\nInvalid Username: Username must begin with a alphabet");
return 0;
}
int validate_password(char string[20],int length)
{
int i=0,flag=1;
if( length<8 )
{
printf("\nWarning: Password too short; must be min 8 chracters long");
return 0;
}
for( i=0 ; (string[i]) != '\0' ; i++ )
{
if( isalnum(string[i]) == 0 )
{
for( i=0 ; (string[i]) != '\0' ; i++ )
{
if( isalpha(string[i]) )
{
flag=0;
break;
}
}
if( flag == 1 )
{
printf("\nWarning: Password too weak; must contain an alphabet");
return 0;
}
for( i=0 ; (string[i]) != '\0' ; i++ )
{
if( isdigit(string[i]) )
{
return 1;
}
}
printf("\nWarning: Password too weak; must contain a digit");
return 0;
}
}
printf("\nWarning: Password too weak; must contain a special character");
return 0;
}