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.
11 /* List of ircd includes from ../include/ */
14 #include "common.h" /* FALSE bleah */
18 #include "s_newconf.h"
29 static int m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
30 int parc
, const char *parv
[]);
31 static int mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
32 int parc
, const char *parv
[]);
33 static char *make_salt(void);
34 static char *make_md5_salt(void);
36 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
39 struct Message mkpasswd_msgtab
= {
40 "MKPASSWD", 0, 0, 0, MFLG_SLOW
,
41 {mg_unreg
, {m_mkpasswd
, 2}, mg_ignore
, mg_ignore
, mg_ignore
, {mo_mkpasswd
, 2}}
44 mapi_clist_av1 mkpasswd_clist
[] = { &mkpasswd_msgtab
, NULL
};
46 DECLARE_MODULE_AV1(mkpasswd
, NULL
, NULL
, mkpasswd_clist
, NULL
, NULL
, "$Revision: 3161 $");
50 m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
52 static time_t last_used
= 0;
55 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
57 /* safe enough to give this on a local connect only */
58 sendto_one(source_p
, form_str(RPL_LOAD2HI
), me
.name
, source_p
->name
, "MKPASSWD");
63 last_used
= rb_current_time();
68 if(!irccmp(parv
[2], "MD5"))
72 else if(!irccmp(parv
[2], "DES"))
74 /* Not really needed, but we may want to have a default encryption
75 * setting somewhere down the road
81 sendto_one_notice(source_p
, ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
87 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MKPASSWD");
89 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
90 parv
[1], rb_crypt(parv
[1],
91 is_md5
? make_md5_salt() :
99 ** parv[1] = parameter
102 mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
108 if(!irccmp(parv
[2], "MD5"))
112 else if(!irccmp(parv
[2], "DES"))
114 /* Not really needed, but we may want to have a default encryption
115 * setting somewhere down the road
121 sendto_one_notice(source_p
,
122 ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
128 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, source_p
->name
, "MKPASSWD");
130 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
131 parv
[1], rb_crypt(parv
[1], is_md5
? make_md5_salt() : make_salt()));
140 salt
[0] = saltChars
[random() % 64];
141 salt
[1] = saltChars
[random() % 64];
149 static char salt
[13];
154 for(i
= 3; i
< 11; i
++)
155 salt
[i
] = saltChars
[random() % 64];