Anope IRC Services  Version 2.0
enc_none.cpp
Go to the documentation of this file.
1 /* Module for plain text encryption.
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * This program is free but copyrighted software; see the file COPYING for
7  * details.
8  */
9 
10 #include "module.h"
11 
12 class ENone : public Module
13 {
14  public:
15  ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR)
16  {
17 
18  }
19 
21  {
22  Anope::string buf = "plain:";
23  Anope::string cpass;
24  Anope::B64Encode(src, cpass);
25  buf += cpass;
26  Log(LOG_DEBUG_2) << "(enc_none) hashed password from [" << src << "] to [" << buf << "]";
27  dest = buf;
28  return EVENT_ALLOW;
29  }
30 
32  {
33  if (!hashm.equals_cs("plain"))
34  return EVENT_CONTINUE;
35  size_t pos = src.find(':');
36  Anope::string buf = src.substr(pos + 1);
37  Anope::B64Decode(buf, dest);
38  return EVENT_ALLOW;
39  }
40 
42  {
43  const NickAlias *na = NickAlias::Find(req->GetAccount());
44  if (na == NULL)
45  return;
46  NickCore *nc = na->nc;
47 
48  size_t pos = nc->pass.find(':');
49  if (pos == Anope::string::npos)
50  return;
51  Anope::string hash_method(nc->pass.begin(), nc->pass.begin() + pos);
52  if (!hash_method.equals_cs("plain"))
53  return;
54 
55  Anope::string buf;
56  this->OnEncrypt(req->GetPassword(), buf);
57  if (nc->pass.equals_cs(buf))
58  {
59  /* if we are NOT the first module in the list,
60  * we want to re-encrypt the pass with the new encryption
61  */
63  Anope::Encrypt(req->GetPassword(), nc->pass);
64  req->Success(this);
65  }
66  }
67 };
68 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
bool equals_cs(const char *_str) const
Definition: anope.h:74
Definition: users.h:34
Anope::string pass
Definition: account.h:115
string substr(size_type pos=0, size_type n=npos) const
Definition: anope.h:277
ENone(const Anope::string &modname, const Anope::string &creator)
Definition: enc_none.cpp:15
CoreExport void B64Encode(const string &src, string &target)
Definition: base64.cpp:82
static const size_type npos
Definition: anope.h:44
CoreExport void B64Decode(const string &src, string &target)
Definition: base64.cpp:123
#define anope_override
Definition: services.h:56
EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) anope_override
Definition: enc_none.cpp:20
EventReturn
Definition: modules.h:129
EventReturn OnDecrypt(const Anope::string &hashm, const Anope::string &src, Anope::string &dest) anope_override
Definition: enc_none.cpp:31
#define MODULE_INIT(x)
Definition: modules.h:45
static Module * FindFirstOf(ModType type)
static Anope::string hashm
Definition: db_old.cpp:123
CoreExport void Encrypt(const Anope::string &src, Anope::string &dest)
Definition: misc.cpp:511
Definition: logger.h:53
iterator begin()
Definition: anope.h:282
size_type find(const string &_str, size_type pos=0) const
Definition: anope.h:192
void OnCheckAuthentication(User *, IdentifyRequest *req) anope_override
Definition: enc_none.cpp:41