diff options
-rw-r--r-- | src/gui/changeemaildialog.cpp | 15 | ||||
-rw-r--r-- | src/gui/changepassworddialog.cpp | 16 | ||||
-rw-r--r-- | src/gui/register.cpp | 44 | ||||
-rw-r--r-- | src/gui/unregisterdialog.cpp | 14 | ||||
-rw-r--r-- | src/main.h | 11 | ||||
-rw-r--r-- | src/net/loginhandler.h | 8 | ||||
-rw-r--r-- | src/net/tmwserv/loginhandler.h | 4 |
7 files changed, 68 insertions, 44 deletions
diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index f536bd4f..32e10e98 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -32,6 +32,8 @@ #include "gui/widgets/textfield.h" #include "net/logindata.h" +#include "net/loginhandler.h" +#include "net/net.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -116,20 +118,21 @@ void ChangeEmailDialog::action(const gcn::ActionEvent &event) std::stringstream errorMessage; int error = 0; - if (newFirstEmail.length() < LEN_MIN_PASSWORD) + unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); + unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); + + if (newFirstEmail.length() < min) { // First email address too short errorMessage << strprintf(_("The new email address needs to be at " - "least %d characters long."), - LEN_MIN_PASSWORD); + "least %d characters long."), min); error = 1; } - else if (newFirstEmail.length() > LEN_MAX_PASSWORD - 1 ) + else if (newFirstEmail.length() > max - 1 ) { // First email address too long errorMessage << strprintf(_("The new email address needs to be " - "less than %d characters long."), - LEN_MAX_PASSWORD); + "less than %d characters long."), max); error = 1; } else if (newFirstEmail != newSecondEmail) diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 0ad9071a..c79db7e9 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -34,6 +34,8 @@ #include "gui/widgets/layout.h" #include "net/logindata.h" +#include "net/loginhandler.h" +#include "net/net.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -98,6 +100,9 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) std::stringstream errorMessage; int error = 0; + unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); + unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); + // Check old Password if (oldPassword.empty()) { @@ -105,19 +110,18 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) errorMessage << _("Enter the old password first."); error = 1; } - else if (newFirstPass.length() < LEN_MIN_PASSWORD) + else if (newFirstPass.length() < min) { // First password too short - errorMessage << strprintf(_("The new password needs to be at least " - "%d characters long."), LEN_MIN_PASSWORD); + errorMessage << strprintf(_("The new password needs to be at least" + " %d characters long."), min); error = 2; } - else if (newFirstPass.length() > LEN_MAX_PASSWORD - 1 ) + else if (newFirstPass.length() > max - 1 ) { // First password too long errorMessage << strprintf(_("The new password needs to be less " - "than %d characters long."), - LEN_MAX_PASSWORD); + "than %d characters long."), max); error = 2; } else if (newFirstPass != newSecondPass) diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 5d9469ca..0ce716bb 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -37,8 +37,8 @@ #include "gui/widgets/textfield.h" #include "net/logindata.h" -#include "net/net.h" #include "net/loginhandler.h" +#include "net/net.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -79,25 +79,32 @@ RegisterDialog::RegisterDialog(LoginData *loginData): place(0, 1, passwordLabel); place(0, 2, confirmLabel); + place(1, 0, mUserField, 3).setPadding(2); + place(1, 1, mPasswordField, 3).setPadding(2); + place(1, 2, mConfirmField, 3).setPadding(2); + + int row = 3; + if (optionalActions & Net::LoginHandler::SetGenderOnRegister) { mMaleButton = new RadioButton(_("Male"), "sex", true); mFemaleButton = new RadioButton(_("Female"), "sex", false); - place(1, 3, mMaleButton); - place(2, 3, mFemaleButton); + place(1, row, mMaleButton); + place(2, row, mFemaleButton); + + row++; } if (optionalActions & Net::LoginHandler::SetEmailOnRegister) { gcn::Label *emailLabel = new Label(_("Email:")); mEmailField = new TextField; - place(0, 3, emailLabel); - place(1, 3, mEmailField, 3).setPadding(2); + place(0, row, emailLabel); + place(1, row, mEmailField, 3).setPadding(2); + + row++; } - place(1, 0, mUserField, 3).setPadding(2); - place(1, 1, mPasswordField, 3).setPadding(2); - place(1, 2, mConfirmField, 3).setPadding(2); place = getPlacer(0, 2); place(1, 0, mRegisterButton); place(2, 0, mCancelButton); @@ -147,36 +154,41 @@ void RegisterDialog::action(const gcn::ActionEvent &event) std::string errorMessage; int error = 0; - if (user.length() < LEN_MIN_USERNAME) + unsigned int minUser = Net::getLoginHandler()->getMinUserNameLength(); + unsigned int maxUser = Net::getLoginHandler()->getMaxUserNameLength(); + unsigned int minPass = Net::getLoginHandler()->getMinPasswordLength(); + unsigned int maxPass = Net::getLoginHandler()->getMaxPasswordLength(); + + if (user.length() < minUser) { // Name too short errorMessage = strprintf (_("The username needs to be at least %d characters long."), - LEN_MIN_USERNAME); + minUser); error = 1; } - else if (user.length() > LEN_MAX_USERNAME - 1 ) + else if (user.length() > maxUser - 1 ) { // Name too long errorMessage = strprintf (_("The username needs to be less than %d characters long."), - LEN_MAX_USERNAME); + maxUser); error = 1; } - else if (mPasswordField->getText().length() < LEN_MIN_PASSWORD) + else if (mPasswordField->getText().length() < minPass) { // Pass too short errorMessage = strprintf (_("The password needs to be at least %d characters long."), - LEN_MIN_PASSWORD); + minPass); error = 2; } - else if (mPasswordField->getText().length() > LEN_MAX_PASSWORD - 1 ) + else if (mPasswordField->getText().length() > maxPass - 1 ) { // Pass too long errorMessage = strprintf (_("The password needs to be less than %d characters long."), - LEN_MAX_PASSWORD); + maxPass); error = 2; } else if (mPasswordField->getText() != mConfirmField->getText()) diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 0dfc8df9..a5e96532 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -34,6 +34,8 @@ #include "gui/widgets/textfield.h" #include "net/logindata.h" +#include "net/loginhandler.h" +#include "net/net.h" #include "utils/gettext.h" #include "utils/stringutils.h" @@ -106,20 +108,22 @@ UnRegisterDialog::action(const gcn::ActionEvent &event) std::stringstream errorMessage; bool error = false; + unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); + unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); + // Check password - if (password.length() < LEN_MIN_PASSWORD) + if (password.length() < min) { // Pass too short errorMessage << strprintf(_("The password needs to be at least %d " - "characters long."), LEN_MIN_PASSWORD); + "characters long."), min); error = true; } - else if (password.length() > LEN_MAX_PASSWORD - 1) + else if (password.length() > max - 1) { // Pass too long errorMessage << strprintf(_("The password needs to be less than " - "%d characters long."), - LEN_MAX_PASSWORD); + "%d characters long."), max); error = true; } @@ -124,17 +124,6 @@ enum State { STATE_FORCE_QUIT }; -/* length definitions for several char[]s in order - * to be able to use strncpy instead of strcpy for - * security and stability reasons - */ -enum { - LEN_MAX_USERNAME = 25, - LEN_MIN_USERNAME = 4, - LEN_MAX_PASSWORD = 25, - LEN_MIN_PASSWORD = 4 -}; - extern State state; extern std::string errorMessage; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index 2ac34c1e..bef88094 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -63,6 +63,14 @@ class LoginHandler */ virtual int supportedOptionalActions() const = 0; + virtual unsigned int getMinUserNameLength() const { return 4; }; + + virtual unsigned int getMaxUserNameLength() const { return 25; }; + + virtual unsigned int getMinPasswordLength() const { return 4; }; + + virtual unsigned int getMaxPasswordLength() const { return 25; }; + virtual void loginAccount(LoginData *loginData) = 0; virtual void logout() = 0; diff --git a/src/net/tmwserv/loginhandler.h b/src/net/tmwserv/loginhandler.h index e9887e1a..ae1e7bfb 100644 --- a/src/net/tmwserv/loginhandler.h +++ b/src/net/tmwserv/loginhandler.h @@ -47,6 +47,10 @@ class LoginHandler : public MessageHandler, public Net::LoginHandler int supportedOptionalActions() const { return Unregister | ChangeEmail | SetEmailOnRegister; } + unsigned int getMaxUserNameLength() const { return 15; }; + + unsigned int getMinPasswordLength() const { return 6; }; + void loginAccount(LoginData *loginData); void logout(); |