From b6665d5eb952b94a12b6630f0da45955bfac0549 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 31 May 2021 21:16:06 +0100 Subject: Add the nickserv:minpasslen option. --- data/nickserv.example.conf | 7 +++++++ docs/Changes.conf | 1 + include/language.h | 3 ++- modules/commands/ns_register.cpp | 3 +++ modules/commands/ns_set.cpp | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/data/nickserv.example.conf b/data/nickserv.example.conf index 53307f33f..667e427b1 100644 --- a/data/nickserv.example.conf +++ b/data/nickserv.example.conf @@ -208,6 +208,13 @@ module */ nonicknameownership = no + /* + * The minimum length of passwords + * + * This directive is optional. If not set it defaults to 8. + */ + minpasslen = 8 + /* * The maximum length of passwords * diff --git a/docs/Changes.conf b/docs/Changes.conf index 6a530436b..9f9802834 100644 --- a/docs/Changes.conf +++ b/docs/Changes.conf @@ -1,5 +1,6 @@ Anope Version 2.1.0-git -------------------- +Added nickserv:minpasslen for configuring the minimum password length. Renamed nickserv:passlen to nickserv:maxpasslen. Anope Version 2.0.10-git diff --git a/include/language.h b/include/language.h index bdf5b3042..3087da802 100644 --- a/include/language.h +++ b/include/language.h @@ -73,7 +73,8 @@ namespace Language #define MORE_OBSCURE_PASSWORD _("Please try again with a more obscure password. Passwords should be at least\n" \ "five characters long, should not be something easily guessed\n" \ "(e.g. your real name or your nick), and cannot contain the space or tab characters.") -#define PASSWORD_TOO_LONG _("Your password is too long. It must not exceed %u characters.") +#define PASSWORD_TOO_SHORT _("Your password is too short. It must must be longer than %u characters.") +#define PASSWORD_TOO_LONG _("Your password is too long. It must be shorter than %u characters.") #define NICK_NOT_REGISTERED _("Your nick isn't registered.") #define NICK_X_NOT_REGISTERED _("Nick \002%s\002 isn't registered.") #define NICK_X_NOT_IN_USE _("Nick \002%s\002 isn't currently in use.") diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index bf59ad1d0..bdbff9386 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -192,6 +192,7 @@ class CommandNSRegister : public Command } } + unsigned int minpasslen = Config->GetModule("nickserv")->Get("minpasslen", "8"); unsigned int maxpasslen = Config->GetModule("nickserv")->Get("maxpasslen", "32"); if (Config->GetModule("nickserv")->Get("forceemail", "yes") && email.empty()) @@ -202,6 +203,8 @@ class CommandNSRegister : public Command source.Reply(NICK_ALREADY_REGISTERED, u_nick.c_str()); else if (pass.equals_ci(u_nick) || (Config->GetBlock("options")->Get("strictpasswords") && pass.length() < 5)) source.Reply(MORE_OBSCURE_PASSWORD); + else if (pass.length() < minpasslen) + source.Reply(PASSWORD_TOO_SHORT, minpasslen); else if (pass.length() > maxpasslen) source.Reply(PASSWORD_TOO_LONG, maxpasslen); else if (!email.empty() && !Mail::Validate(email)) diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 22f74703c..8008bd5d4 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -137,6 +137,13 @@ class CommandNSSetPassword : public Command return; } + unsigned int minpasslen = Config->GetModule("nickserv")->Get("minpasslen", "8"); + if (len < minpasslen) + { + source.Reply(PASSWORD_TOO_SHORT, minpasslen); + return; + } + unsigned int maxpasslen = Config->GetModule("nickserv")->Get("maxpasslen", "32"); if (len > maxpasslen) { @@ -199,6 +206,13 @@ class CommandNSSASetPassword : public Command return; } + unsigned int minpasslen = Config->GetModule("nickserv")->Get("minpasslen", "8"); + if (len < minpasslen) + { + source.Reply(PASSWORD_TOO_SHORT, minpasslen); + return; + } + unsigned int maxpasslen = Config->GetModule("nickserv")->Get("maxpasslen", "32"); if (len > maxpasslen) { -- cgit