2 * m_mkpasswd.c: Encrypts a password online, DES or MD5.
4 * Copyright 2002 W. Campbell and the ircd-ratbox development team
5 * Based on mkpasswd.c, originally by Nelson Minar (minar@reed.edu)
7 * You can use this code in any way as long as these names remain.
9 * $Id: m_mkpasswd.c 3161 2007-01-25 07:23:01Z nenolod $
12 /* List of ircd includes from ../include/ */
15 #include "common.h" /* FALSE bleah */
17 #include "irc_string.h"
20 #include "s_newconf.h"
33 static int m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
34 int parc
, const char *parv
[]);
35 static int mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
36 int parc
, const char *parv
[]);
37 static char *make_salt(void);
38 static char *make_md5_salt(void);
40 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
43 struct Message mkpasswd_msgtab
= {
44 "MKPASSWD", 0, 0, 0, MFLG_SLOW
,
45 {mg_unreg
, {m_mkpasswd
, 2}, mg_ignore
, mg_ignore
, mg_ignore
, {mo_mkpasswd
, 2}}
48 mapi_clist_av1 mkpasswd_clist
[] = { &mkpasswd_msgtab
, NULL
};
50 DECLARE_MODULE_AV1(mkpasswd
, NULL
, NULL
, mkpasswd_clist
, NULL
, NULL
, "$Revision: 3161 $");
54 m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
56 static time_t last_used
= 0;
59 if((last_used
+ ConfigFileEntry
.pace_wait
) > CurrentTime
)
61 /* safe enough to give this on a local connect only */
62 sendto_one(source_p
, form_str(RPL_LOAD2HI
), me
.name
, parv
[0]);
67 last_used
= CurrentTime
;
72 if(!irccmp(parv
[2], "MD5"))
76 else if(!irccmp(parv
[2], "DES"))
78 /* Not really needed, but we may want to have a default encryption
79 * setting somewhere down the road
85 sendto_one_notice(source_p
, ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
91 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, parv
[0], "MKPASSWD");
93 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
94 parv
[1], crypt(parv
[1],
95 is_md5
? make_md5_salt() :
103 ** parv[0] = sender prefix
104 ** parv[1] = parameter
107 mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
113 if(!irccmp(parv
[2], "MD5"))
117 else if(!irccmp(parv
[2], "DES"))
119 /* Not really needed, but we may want to have a default encryption
120 * setting somewhere down the road
126 sendto_one_notice(source_p
,
127 ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
133 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, parv
[0], "MKPASSWD");
135 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
136 parv
[1], crypt(parv
[1], is_md5
? make_md5_salt() : make_salt()));
145 salt
[0] = saltChars
[random() % 64];
146 salt
[1] = saltChars
[random() % 64];
154 static char salt
[13];
159 for(i
= 3; i
< 11; i
++)
160 salt
[i
] = saltChars
[random() % 64];