mirror of
https://github.com/anope/anope.git
synced 2026-06-23 07:06:38 +02:00
e66063e630
up into seperate files for each pseudo client. Also reorganized how the modules are stored, and made most of the old "extra" modules "core"
75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
/* Module for plain text encryption.
|
|
*
|
|
* (C) 2003-2011 Anope Team
|
|
* Contact us at team@anope.org
|
|
*
|
|
* This program is free but copyrighted software; see the file COPYING for
|
|
* details.
|
|
*/
|
|
|
|
#include "module.h"
|
|
|
|
class ENone : public Module
|
|
{
|
|
public:
|
|
ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION)
|
|
{
|
|
this->SetAuthor("Anope");
|
|
|
|
Implementation i[] = { I_OnEncrypt, I_OnDecrypt, I_OnCheckAuthentication };
|
|
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
|
|
}
|
|
|
|
EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest)
|
|
{
|
|
Anope::string buf = "plain:";
|
|
Anope::string cpass;
|
|
Anope::B64Encode(src, cpass);
|
|
buf += cpass;
|
|
Log(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]";
|
|
dest = buf;
|
|
return EVENT_ALLOW;
|
|
}
|
|
|
|
EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest)
|
|
{
|
|
if (!hashm.equals_cs("plain"))
|
|
return EVENT_CONTINUE;
|
|
size_t pos = src.find(':');
|
|
Anope::string buf = src.substr(pos + 1);
|
|
Anope::B64Decode(buf, dest);
|
|
return EVENT_ALLOW;
|
|
}
|
|
|
|
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> ¶ms, const Anope::string &account, const Anope::string &password)
|
|
{
|
|
NickAlias *na = findnick(account);
|
|
NickCore *nc = na ? na->nc : NULL;
|
|
if (na == NULL)
|
|
return EVENT_CONTINUE;
|
|
|
|
size_t pos = nc->pass.find(':');
|
|
if (pos == Anope::string::npos)
|
|
return EVENT_CONTINUE;
|
|
Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
|
|
if (!hash_method.equals_cs("plain"))
|
|
return EVENT_CONTINUE;
|
|
|
|
Anope::string buf;
|
|
this->OnEncrypt(password, buf);
|
|
if (nc->pass.equals_cs(buf))
|
|
{
|
|
/* if we are NOT the first module in the list,
|
|
* we want to re-encrypt the pass with the new encryption
|
|
*/
|
|
if (ModuleManager::FindFirstOf(ENCRYPTION) != this)
|
|
enc_encrypt(password, nc->pass);
|
|
return EVENT_ALLOW;
|
|
}
|
|
|
|
return EVENT_CONTINUE;
|
|
}
|
|
};
|
|
|
|
MODULE_INIT(ENone)
|