1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 /* $ModDesc: Allows for hashed oper passwords */
21 class CommandMkpasswd : public Command
24 CommandMkpasswd(Module* Creator) : Command(Creator, "MKPASSWD", 2)
26 syntax = "<hashtype> <any-text>";
30 void MakeHash(User* user, const std::string& algo, const std::string& stuff)
32 HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + algo);
35 /* Now attempt to generate a hash */
36 user->WriteServ("NOTICE %s :%s hashed password for %s is %s",
37 user->nick.c_str(), algo.c_str(), stuff.c_str(), hp->hexsum(stuff).c_str());
41 /* I dont do flying, bob. */
42 user->WriteServ("NOTICE %s :Unknown hash type", user->nick.c_str());
46 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
48 MakeHash(user, parameters[0], parameters[1]);
54 class ModuleOperHash : public Module
59 ModuleOperHash() : cmd(this)
61 /* Read the config file first */
64 ServerInstance->AddCommand(&cmd);
65 Implementation eventlist[] = { I_OnPassCompare };
66 ServerInstance->Modules->Attach(eventlist, this, 1);
69 virtual ModResult OnPassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype)
71 HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + hashtype);
73 /* Is this a valid hash name? */
76 /* Compare the hash in the config to the generated hash */
77 if (data == hp->hexsum(input))
80 /* No match, and must be hashed, forbid */
84 /* Not a hash, fall through to strcmp in core */
85 return MOD_RES_PASSTHRU;
88 virtual Version GetVersion()
90 return Version("Allows for hashed oper passwords",VF_VENDOR);
94 MODULE_INIT(ModuleOperHash)