Validate password before form submitting

Hi,
Im trying to create a custom sign up lightbox for new members to sign up.
Everything works fine but the problem is that the form still gets submitted even when the password is invalid. in fact, all input fields has a field in the database except password of course thats why password is not taken in consideration when hitting submit.
Any idea how to solve this?
Thanks in Advance.

Thats how the code looks like:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
$w.onReady( function () {
let email = $w(‘#emailInput’).value
let password = $w(‘#passwordInput’).value
let firstName = $w(‘#firstName’).value
let lastName = $w(‘#lastName’).value
let phone = $w(‘#phone’).value
let adress = $w(‘#address’).value

const validateEmail = (otherEmailElementId) => (value, reject) => {
let otherEmailElement = $w(otherEmailElementId);
if (value === otherEmailElement.value) {
otherEmailElement.validity.valid = true ;
otherEmailElement.resetValidityIndication();
return ;
}
console.log(“Email and Confirm Your Email fields do not match”);
otherEmailElement.validity.valid = false ;
otherEmailElement.updateValidityIndication();
reject(“Email and Confirm Email fields do not match”);
};

$w(“#emailConfirmInput”).onCustomValidation(validateEmail(“#emailInput”));
$w(“#emailInput”).onCustomValidation(validateEmail(“#emailConfirmInput”));

const validatePassword = (otherPasswordElementId) => (value, reject) => {
let otherPasswordElement = $w(otherPasswordElementId);
if (value === otherPasswordElement.value) {
otherPasswordElement.validity.valid = true ;
otherPasswordElement.resetValidityIndication();
return ;
}
console.log(“Password and Confirm Your Password fields do not match”);
otherPasswordElement.validity.valid = false ;
otherPasswordElement.updateValidityIndication();
reject(“Password and Confirm Password fields do not match”);
};

$w(“#passwordConfirmInput”).onCustomValidation(validatePassword(“#passwordInput”));
$w(“#passwordInput”).onCustomValidation(validatePassword(“#passwordConfirmInput”));

$w(“#PaidMembersDB”).onBeforeSave((event) => {
if (!($w(‘#firstName’).valid && $w(‘#lastName’).valid && $w(‘#emailInput’).valid)) {
if (!$w(‘#firstName’).valid || !$w(‘#lastName’).valid)
$w(‘#NoName’).show();
if (!$w(‘#emailInput’).valid) {
if (!$w(‘#emailInput’).value)
$w(‘#NoEmail’).show();
else if ($w(‘#emailInput’).value !== $w(“#emailConfirmInput”).value) {
$w(‘#EmailsNotMatch’).show();
}
}
if (!$w(‘#passwordInput’).valid) {
if (!$w(‘#passwordInput’).value)
$w(‘#NoPassword’).show();
else if ($w(‘#passwordInput’).value !== $w(“#passwordConfirmInput”).value) {
$w(‘#PasswordNotMatch’).show();
}
}
}
});
});
export function firstName_change(event) {
$w(‘#NoName’).hide();
}
export function lastName_change(event) {
$w(‘#lastName’).hide();
}
export function emailInput_change(event) {
$w(‘#NoEmail’).hide();
}
export function passwordInput_change(event) {
$w(‘#NoPassword’).hide();
}

There is no field for password as nobody has access to site members passwords. This is done for security and safety reasons and you should never set up a dataset on your site to store users passwords either.

You are using the Wix example here and it does not validate the password entered by the user.
https://www.wix.com/corvid/example/custom-validations

However, there are previous forum posts too that will get around this.
https://www.wix.com/corvid/forum/community-discussion/confirm-password
https://www.wix.com/corvid/forum/community-discussion/trying-to-validate-password-without-success
https://www.wix.com/corvid/forum/community-discussion/how-to-compare-the-password-field-with-retype-password-field

Hi, thanks for your reply, I read all the posts in the forum that discuss this subject but couldn’t get it to work. As I said I know that its not safe to keep the passwords in the database that why the password input field stays disconected and when Im clicking submit the form is being submited even thogh the password is not confirmed yet.

You should use the solution Anders describes here : https://www.wix.com/corvid/forum/community-discussion/how-to-compare-the-password-field-with-retype-password-field . It would show you how it´s done.

One example of this is that I´m currently running with is:

First we store the 1st password:

export function Input_Change(event) {
// Code that runs when first password input has been entered
let password1 = $w('#input1).value;
}

Then on the “confirm password” we do the following:

export function Input2_Change(event) {
password2 = $w(‘#dinput2’).value;
if (password1===password2) {
$w(‘#button3’).enable(); /// Enables a button that allows the user to create account
$w(‘#button3’).label= “Create account”

} else { $w(‘#button3’).label = “Oppsies, your passwords does not match. Please try again”
}

Please let me know if you need more info :slight_smile:

Thanks for your reply, I couldn’t get it to work unfortunately…