Set-password stage (registration and reset): enforce the password policy, derive the SRP {salt, verifier} in the browser, and submit only those — the password itself never leaves this page.
/* Set-password stage (registration and reset): enforce the password policy, * derive the SRP {salt, verifier} in the browser, and submit only those — * the password itself never leaves this page. */'use strict';(()=>{constform=document.getElementById('password-form');if(!form)return;consterrorBox=document.getElementById('form-error');constsubmit=document.getElementById('submit-btn');constMIN_LENGTH=16;// keep in sync with packages/site/euler_site/auth/policy.pyfunctionfail(message){errorBox.textContent=message;errorBox.hidden=false;submit.disabled=false;}functionpolicyError(password){if(password.length<MIN_LENGTH)return`Use at least ${MIN_LENGTH} characters.`;constclasses=[/[a-z]/,/[A-Z]/,/[0-9]/,/[^a-zA-Z0-9]/];if(!classes.every(re=>re.test(password))){return'Use all four classes: lowercase, uppercase, digits, and specials.';}returnnull;}form.addEventListener('submit',async(event)=>{event.preventDefault();errorBox.hidden=true;submit.disabled=true;constpassword=document.getElementById('password').value;constconfirm=document.getElementById('confirm').value;if(password!==confirm)returnfail('The passwords do not match.');constproblem=policyError(password);if(problem)returnfail(problem);try{const{salt,verifier,kdf}=awaitSRP.computeVerifier(form.dataset.email,password);form.elements.salt.value=salt;form.elements.verifier.value=verifier;form.elements.kdf.value=kdf;document.getElementById('password').value='';document.getElementById('confirm').value='';// Prototype call: immune to named form controls shadowing .submit().HTMLFormElement.prototype.submit.call(form);}catch(err){fail('Could not derive the verifier: '+(err&&err.message?err.message:'unexpected error'));}});})();