-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpasswd.c
71 lines (62 loc) · 1.81 KB
/
passwd.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
/*
Eagles Bulletin Board System
Copyright (C) 1995, Ray Rocker, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "common.h"
#include <time.h>
#if NEEDS_CRYPT_DECLARED
char *crypt __P((char *, char *));
#else
# include <unistd.h>
#endif
#define REALPASSLEN 8 /* number of significant characters */
is_passwd_good(crypted, clear)
char *crypted;
char *clear;
{
char *pw;
char copy[REALPASSLEN+1];
memset(copy, 0, sizeof copy);
strncpy(copy, clear, REALPASSLEN);
pw = crypt(copy, crypted);
return (!strcmp(pw, crypted));
}
void
encrypt_passwd(crypted, clear)
char *crypted;
char *clear;
{
char copy[REALPASSLEN+1];
char saltc[2];
time_t now;
char *pw;
int i;
if (*clear == '\0') {
*crypted = '\0';
return;
}
memset(copy, 0, sizeof copy);
strncpy(copy, clear, REALPASSLEN);
time(&now);
saltc[0] = (char)(now & 000177);
saltc[1] = (char)((now >> 7) & 000177);
for (i=0; i<2; i++) {
if (saltc[i] < 0x2e) saltc[i]+=0x41;
if (saltc[i] > 0x39 && saltc[i] < 0x41) saltc[i]-=0x7;
if (saltc[i] > 0x5a && saltc[i] < 0x61) saltc[i]+=0x6;
if (saltc[i] > 0x7a) saltc[i]-=0x5;
}
pw = crypt(copy, saltc);
strncpy(crypted, pw, PASSLEN);
}