Commit 7fc4b120bf35daa5d3d96eb565ec7d79ce153653
- Diff rendering mode:
- inline
- side by side
|   | |||
| 32 | 32 | #include "gui/widgets/textfield.h" | |
| 33 | 33 | ||
| 34 | 34 | #include "net/logindata.h" | |
| 35 | #include "net/loginhandler.h" | ||
| 36 | #include "net/net.h" | ||
| 35 | 37 | ||
| 36 | 38 | #include "utils/gettext.h" | |
| 37 | 39 | #include "utils/stringutils.h" | |
| … | … | ||
| 118 | 118 | std::stringstream errorMessage; | |
| 119 | 119 | int error = 0; | |
| 120 | 120 | ||
| 121 | if (newFirstEmail.length() < LEN_MIN_PASSWORD) | ||
| 121 | unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); | ||
| 122 | unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); | ||
| 123 | |||
| 124 | if (newFirstEmail.length() < min) | ||
| 122 | 125 | { | |
| 123 | 126 | // First email address too short | |
| 124 | 127 | errorMessage << strprintf(_("The new email address needs to be at " | |
| 125 | "least %d characters long."), | ||
| 126 | LEN_MIN_PASSWORD); | ||
| 128 | "least %d characters long."), min); | ||
| 127 | 129 | error = 1; | |
| 128 | 130 | } | |
| 129 | else if (newFirstEmail.length() > LEN_MAX_PASSWORD - 1 ) | ||
| 131 | else if (newFirstEmail.length() > max - 1 ) | ||
| 130 | 132 | { | |
| 131 | 133 | // First email address too long | |
| 132 | 134 | errorMessage << strprintf(_("The new email address needs to be " | |
| 133 | "less than %d characters long."), | ||
| 134 | LEN_MAX_PASSWORD); | ||
| 135 | "less than %d characters long."), max); | ||
| 135 | 136 | error = 1; | |
| 136 | 137 | } | |
| 137 | 138 | else if (newFirstEmail != newSecondEmail) |
src/gui/changepassworddialog.cpp
(10 / 6)
|   | |||
| 34 | 34 | #include "gui/widgets/layout.h" | |
| 35 | 35 | ||
| 36 | 36 | #include "net/logindata.h" | |
| 37 | #include "net/loginhandler.h" | ||
| 38 | #include "net/net.h" | ||
| 37 | 39 | ||
| 38 | 40 | #include "utils/gettext.h" | |
| 39 | 41 | #include "utils/stringutils.h" | |
| … | … | ||
| 100 | 100 | std::stringstream errorMessage; | |
| 101 | 101 | int error = 0; | |
| 102 | 102 | ||
| 103 | unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); | ||
| 104 | unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); | ||
| 105 | |||
| 103 | 106 | // Check old Password | |
| 104 | 107 | if (oldPassword.empty()) | |
| 105 | 108 | { | |
| … | … | ||
| 110 | 110 | errorMessage << _("Enter the old password first."); | |
| 111 | 111 | error = 1; | |
| 112 | 112 | } | |
| 113 | else if (newFirstPass.length() < LEN_MIN_PASSWORD) | ||
| 113 | else if (newFirstPass.length() < min) | ||
| 114 | 114 | { | |
| 115 | 115 | // First password too short | |
| 116 | errorMessage << strprintf(_("The new password needs to be at least " | ||
| 117 | "%d characters long."), LEN_MIN_PASSWORD); | ||
| 116 | errorMessage << strprintf(_("The new password needs to be at least" | ||
| 117 | " %d characters long."), min); | ||
| 118 | 118 | error = 2; | |
| 119 | 119 | } | |
| 120 | else if (newFirstPass.length() > LEN_MAX_PASSWORD - 1 ) | ||
| 120 | else if (newFirstPass.length() > max - 1 ) | ||
| 121 | 121 | { | |
| 122 | 122 | // First password too long | |
| 123 | 123 | errorMessage << strprintf(_("The new password needs to be less " | |
| 124 | "than %d characters long."), | ||
| 125 | LEN_MAX_PASSWORD); | ||
| 124 | "than %d characters long."), max); | ||
| 126 | 125 | error = 2; | |
| 127 | 126 | } | |
| 128 | 127 | else if (newFirstPass != newSecondPass) |
src/gui/register.cpp
(28 / 16)
|   | |||
| 37 | 37 | #include "gui/widgets/textfield.h" | |
| 38 | 38 | ||
| 39 | 39 | #include "net/logindata.h" | |
| 40 | #include "net/net.h" | ||
| 41 | 40 | #include "net/loginhandler.h" | |
| 41 | #include "net/net.h" | ||
| 42 | 42 | ||
| 43 | 43 | #include "utils/gettext.h" | |
| 44 | 44 | #include "utils/stringutils.h" | |
| … | … | ||
| 79 | 79 | place(0, 1, passwordLabel); | |
| 80 | 80 | place(0, 2, confirmLabel); | |
| 81 | 81 | ||
| 82 | place(1, 0, mUserField, 3).setPadding(2); | ||
| 83 | place(1, 1, mPasswordField, 3).setPadding(2); | ||
| 84 | place(1, 2, mConfirmField, 3).setPadding(2); | ||
| 85 | |||
| 86 | int row = 3; | ||
| 87 | |||
| 82 | 88 | if (optionalActions & Net::LoginHandler::SetGenderOnRegister) | |
| 83 | 89 | { | |
| 84 | 90 | mMaleButton = new RadioButton(_("Male"), "sex", true); | |
| 85 | 91 | mFemaleButton = new RadioButton(_("Female"), "sex", false); | |
| 86 | place(1, 3, mMaleButton); | ||
| 87 | place(2, 3, mFemaleButton); | ||
| 92 | place(1, row, mMaleButton); | ||
| 93 | place(2, row, mFemaleButton); | ||
| 94 | |||
| 95 | row++; | ||
| 88 | 96 | } | |
| 89 | 97 | ||
| 90 | 98 | if (optionalActions & Net::LoginHandler::SetEmailOnRegister) | |
| 91 | 99 | { | |
| 92 | 100 | gcn::Label *emailLabel = new Label(_("Email:")); | |
| 93 | 101 | mEmailField = new TextField; | |
| 94 | place(0, 3, emailLabel); | ||
| 95 | place(1, 3, mEmailField, 3).setPadding(2); | ||
| 102 | place(0, row, emailLabel); | ||
| 103 | place(1, row, mEmailField, 3).setPadding(2); | ||
| 104 | |||
| 105 | row++; | ||
| 96 | 106 | } | |
| 97 | 107 | ||
| 98 | place(1, 0, mUserField, 3).setPadding(2); | ||
| 99 | place(1, 1, mPasswordField, 3).setPadding(2); | ||
| 100 | place(1, 2, mConfirmField, 3).setPadding(2); | ||
| 101 | 108 | place = getPlacer(0, 2); | |
| 102 | 109 | place(1, 0, mRegisterButton); | |
| 103 | 110 | place(2, 0, mCancelButton); | |
| … | … | ||
| 154 | 154 | std::string errorMessage; | |
| 155 | 155 | int error = 0; | |
| 156 | 156 | ||
| 157 | if (user.length() < LEN_MIN_USERNAME) | ||
| 157 | unsigned int minUser = Net::getLoginHandler()->getMinUserNameLength(); | ||
| 158 | unsigned int maxUser = Net::getLoginHandler()->getMaxUserNameLength(); | ||
| 159 | unsigned int minPass = Net::getLoginHandler()->getMinPasswordLength(); | ||
| 160 | unsigned int maxPass = Net::getLoginHandler()->getMaxPasswordLength(); | ||
| 161 | |||
| 162 | if (user.length() < minUser) | ||
| 158 | 163 | { | |
| 159 | 164 | // Name too short | |
| 160 | 165 | errorMessage = strprintf | |
| 161 | 166 | (_("The username needs to be at least %d characters long."), | |
| 162 | LEN_MIN_USERNAME); | ||
| 167 | minUser); | ||
| 163 | 168 | error = 1; | |
| 164 | 169 | } | |
| 165 | else if (user.length() > LEN_MAX_USERNAME - 1 ) | ||
| 170 | else if (user.length() > maxUser - 1 ) | ||
| 166 | 171 | { | |
| 167 | 172 | // Name too long | |
| 168 | 173 | errorMessage = strprintf | |
| 169 | 174 | (_("The username needs to be less than %d characters long."), | |
| 170 | LEN_MAX_USERNAME); | ||
| 175 | maxUser); | ||
| 171 | 176 | error = 1; | |
| 172 | 177 | } | |
| 173 | else if (mPasswordField->getText().length() < LEN_MIN_PASSWORD) | ||
| 178 | else if (mPasswordField->getText().length() < minPass) | ||
| 174 | 179 | { | |
| 175 | 180 | // Pass too short | |
| 176 | 181 | errorMessage = strprintf | |
| 177 | 182 | (_("The password needs to be at least %d characters long."), | |
| 178 | LEN_MIN_PASSWORD); | ||
| 183 | minPass); | ||
| 179 | 184 | error = 2; | |
| 180 | 185 | } | |
| 181 | else if (mPasswordField->getText().length() > LEN_MAX_PASSWORD - 1 ) | ||
| 186 | else if (mPasswordField->getText().length() > maxPass - 1 ) | ||
| 182 | 187 | { | |
| 183 | 188 | // Pass too long | |
| 184 | 189 | errorMessage = strprintf | |
| 185 | 190 | (_("The password needs to be less than %d characters long."), | |
| 186 | LEN_MAX_PASSWORD); | ||
| 191 | maxPass); | ||
| 187 | 192 | error = 2; | |
| 188 | 193 | } | |
| 189 | 194 | else if (mPasswordField->getText() != mConfirmField->getText()) |
src/gui/unregisterdialog.cpp
(9 / 5)
|   | |||
| 34 | 34 | #include "gui/widgets/textfield.h" | |
| 35 | 35 | ||
| 36 | 36 | #include "net/logindata.h" | |
| 37 | #include "net/loginhandler.h" | ||
| 38 | #include "net/net.h" | ||
| 37 | 39 | ||
| 38 | 40 | #include "utils/gettext.h" | |
| 39 | 41 | #include "utils/stringutils.h" | |
| … | … | ||
| 108 | 108 | std::stringstream errorMessage; | |
| 109 | 109 | bool error = false; | |
| 110 | 110 | ||
| 111 | unsigned int min = Net::getLoginHandler()->getMinPasswordLength(); | ||
| 112 | unsigned int max = Net::getLoginHandler()->getMaxPasswordLength(); | ||
| 113 | |||
| 111 | 114 | // Check password | |
| 112 | if (password.length() < LEN_MIN_PASSWORD) | ||
| 115 | if (password.length() < min) | ||
| 113 | 116 | { | |
| 114 | 117 | // Pass too short | |
| 115 | 118 | errorMessage << strprintf(_("The password needs to be at least %d " | |
| 116 | "characters long."), LEN_MIN_PASSWORD); | ||
| 119 | "characters long."), min); | ||
| 117 | 120 | error = true; | |
| 118 | 121 | } | |
| 119 | else if (password.length() > LEN_MAX_PASSWORD - 1) | ||
| 122 | else if (password.length() > max - 1) | ||
| 120 | 123 | { | |
| 121 | 124 | // Pass too long | |
| 122 | 125 | errorMessage << strprintf(_("The password needs to be less than " | |
| 123 | "%d characters long."), | ||
| 124 | LEN_MAX_PASSWORD); | ||
| 126 | "%d characters long."), max); | ||
| 125 | 127 | error = true; | |
| 126 | 128 | } | |
| 127 | 129 |
src/main.h
(0 / 11)
|   | |||
| 124 | 124 | STATE_FORCE_QUIT | |
| 125 | 125 | }; | |
| 126 | 126 | ||
| 127 | /* length definitions for several char[]s in order | ||
| 128 | * to be able to use strncpy instead of strcpy for | ||
| 129 | * security and stability reasons | ||
| 130 | */ | ||
| 131 | enum { | ||
| 132 | LEN_MAX_USERNAME = 25, | ||
| 133 | LEN_MIN_USERNAME = 4, | ||
| 134 | LEN_MAX_PASSWORD = 25, | ||
| 135 | LEN_MIN_PASSWORD = 4 | ||
| 136 | }; | ||
| 137 | |||
| 138 | 127 | extern State state; | |
| 139 | 128 | extern std::string errorMessage; | |
| 140 | 129 |
src/net/loginhandler.h
(8 / 0)
|   | |||
| 63 | 63 | */ | |
| 64 | 64 | virtual int supportedOptionalActions() const = 0; | |
| 65 | 65 | ||
| 66 | virtual unsigned int getMinUserNameLength() const { return 4; }; | ||
| 67 | |||
| 68 | virtual unsigned int getMaxUserNameLength() const { return 25; }; | ||
| 69 | |||
| 70 | virtual unsigned int getMinPasswordLength() const { return 4; }; | ||
| 71 | |||
| 72 | virtual unsigned int getMaxPasswordLength() const { return 25; }; | ||
| 73 | |||
| 66 | 74 | virtual void loginAccount(LoginData *loginData) = 0; | |
| 67 | 75 | ||
| 68 | 76 | virtual void logout() = 0; |
|   | |||
| 47 | 47 | int supportedOptionalActions() const | |
| 48 | 48 | { return Unregister | ChangeEmail | SetEmailOnRegister; } | |
| 49 | 49 | ||
| 50 | unsigned int getMaxUserNameLength() const { return 15; }; | ||
| 51 | |||
| 52 | unsigned int getMinPasswordLength() const { return 6; }; | ||
| 53 | |||
| 50 | 54 | void loginAccount(LoginData *loginData); | |
| 51 | 55 | ||
| 52 | 56 | void logout(); |

