I have modified the javascript "register.js" at plugins/com.openexchange.user.passwordchange. The password-Validation is now directly at the gui. Only thing i have to to now is to modifiy the translation files to get localised error messages.
Maybe you can implement the code in ox in the next version or something like that?
Here the complete code:
/*
* All content on this website (including text, images, source
* code and any other original works), unless otherwise noted,
* is licensed under a Creative Commons License.
*
* http://creativecommons.org/licenses/by-nc-sa/2.5/
*
* Copyright (C) 2004-2010 Open-Xchange, Inc.
* Mail: info@open-xchange.com
*/
// following parameter enables checks, valid values are true/false
var check_length = false
var check_lowercase = true
var check_uppercase = true
var check_number = true
// configure password-checks
var minLength = "8"
var lowercases = "abcdefghijklmnopqrstuvwxyz"
var uppercases = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var numbers = "1234567890"
new ox.Configuration.InnerNode("configuration/user", _("User"));
var node = new ox.Configuration.LeafNode("configuration/user/password",
_("Password"));
var page = new ox.Configuration.Page(node, _("Change Password"));
var intro = new ox.UI.Text(_("Choose a new password for your account."));
page.addWidget(intro);
var pass_old = new ox.UI.Password(_("Your old password"));
page.addWidget(pass_old, "old_password");
var pass_new = new ox.UI.Password(_("The new password"));
page.addWidget(pass_new, "new_password");
var pass_new2 = new ox.UI.Password(_("Confirm new password"));
page.addWidget(pass_new2, "new_password2");
page.save = function (data, cont) {
function emptyPass() {
ox.Configuration.error(_("Please enter your old password and twice the new password."));
}
if (pass_old.get() == "") {
pass_old.formnode.focus();
return emptyPass();
} else if (pass_new.get() == "") {
pass_new.formnode.focus();
return emptyPass();
} else if (pass_new2.get() == "") {
pass_new2.formnode.focus();
return emptyPass();
} else if (pass_new.get() != pass_new2.get()) {
pass_new.formnode.focus();
ox.Configuration.error(_("The two newly entered passwords do not match."));
return;
} else if (check_length == true && pass_new.get().length < minLength) {
ox.Configuration.error(_("The password length is below min length (" + minLength + ")"));
return;
} else if (check_lowercase == true && contains(pass_new.get(),lowercases) == false ){
ox.Configuration.error(_("The password does not contain characters with lower cases"));
return;
} else if (check_uppercase == true && contains(pass_new.get(),uppercases) == false ){
ox.Configuration.error(_("The password does not contain characters with upper cases"));
return;
} else if (check_number == true && contains(pass_new.get(),numbers) == false ){
ox.Configuration.error(_("The password does not contain numbers"));
return;
}
ox.JSON.put(AjaxRoot+"/passwordchange?action=update&session="+session,dat a,
function() {
ox.Configuration.info(
_("Your new password has been saved."));
cont();
});
}
// sees if a password contains one of a set of characters
function contains(password, validChars) {
for (i = 0; i < password.length; i++) {
var char = password.charAt(i);
if (validChars.indexOf(char) > -1) {
return true;
}
}
return false;
}
* All content on this website (including text, images, source
* code and any other original works), unless otherwise noted,
* is licensed under a Creative Commons License.
*
* http://creativecommons.org/licenses/by-nc-sa/2.5/
*
* Copyright (C) 2004-2010 Open-Xchange, Inc.
* Mail: info@open-xchange.com
*/
// following parameter enables checks, valid values are true/false
var check_length = false
var check_lowercase = true
var check_uppercase = true
var check_number = true
// configure password-checks
var minLength = "8"
var lowercases = "abcdefghijklmnopqrstuvwxyz"
var uppercases = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var numbers = "1234567890"
new ox.Configuration.InnerNode("configuration/user", _("User"));
var node = new ox.Configuration.LeafNode("configuration/user/password",
_("Password"));
var page = new ox.Configuration.Page(node, _("Change Password"));
var intro = new ox.UI.Text(_("Choose a new password for your account."));
page.addWidget(intro);
var pass_old = new ox.UI.Password(_("Your old password"));
page.addWidget(pass_old, "old_password");
var pass_new = new ox.UI.Password(_("The new password"));
page.addWidget(pass_new, "new_password");
var pass_new2 = new ox.UI.Password(_("Confirm new password"));
page.addWidget(pass_new2, "new_password2");
page.save = function (data, cont) {
function emptyPass() {
ox.Configuration.error(_("Please enter your old password and twice the new password."));
}
if (pass_old.get() == "") {
pass_old.formnode.focus();
return emptyPass();
} else if (pass_new.get() == "") {
pass_new.formnode.focus();
return emptyPass();
} else if (pass_new2.get() == "") {
pass_new2.formnode.focus();
return emptyPass();
} else if (pass_new.get() != pass_new2.get()) {
pass_new.formnode.focus();
ox.Configuration.error(_("The two newly entered passwords do not match."));
return;
} else if (check_length == true && pass_new.get().length < minLength) {
ox.Configuration.error(_("The password length is below min length (" + minLength + ")"));
return;
} else if (check_lowercase == true && contains(pass_new.get(),lowercases) == false ){
ox.Configuration.error(_("The password does not contain characters with lower cases"));
return;
} else if (check_uppercase == true && contains(pass_new.get(),uppercases) == false ){
ox.Configuration.error(_("The password does not contain characters with upper cases"));
return;
} else if (check_number == true && contains(pass_new.get(),numbers) == false ){
ox.Configuration.error(_("The password does not contain numbers"));
return;
}
ox.JSON.put(AjaxRoot+"/passwordchange?action=update&session="+session,dat a,
function() {
ox.Configuration.info(
_("Your new password has been saved."));
cont();
});
}
// sees if a password contains one of a set of characters
function contains(password, validChars) {
for (i = 0; i < password.length; i++) {
var char = password.charAt(i);
if (validChars.indexOf(char) > -1) {
return true;
}
}
return false;
}
Leave a comment: