TypeError: c is undefined only with register/change_pwd
ChazyTheBest opened this issue · comments
I just implemented jsSHA512 in my website and I'm having trouble in the register function. It's working ok with the simple login function.
This is the error I'm getting in the firefox console:
TypeError: c is undefined sha512.js:22:137
A/c() sha512.js:22
w/this.update() sha512.js:14
window.onload/<() _display:60
jQuery.event.dispatch() jquery-2.1.4.js:4434
jQuery.event.add/elemData.handle() jquery-2.1.4.js:4121
https://jsfiddle.net/pa9sgx3v/2/
$(function () {
var a = $('form#login'),
b = $('form#register'),
c = $('form#change_pwd'),
shaObj = new jsSHA('SHA-512', 'TEXT');
a.on('submit', function (e) {
e.preventDefault();
var p = $('#password');
shaObj.update(p.val());
var p_hash = shaObj.getHash("HEX");
p.val(p_hash);
this.submit()
});
b.on('submit', function (e) {
e.preventDefault();
var p = $('#reg_pwd'),
q = $('#confirm_pwd');
shaObj.update(p.val());
var p_hash = shaObj.getHash("HEX");
p.val(p_hash);
shaObj.update(q.val());
var q_hash = shaObj.getHash("HEX");
q.val(q_hash);
this.submit()
});
c.on('submit', function (e) {
e.preventDefault();
var p = $('#current_pwd'),
q = $('#new_pwd'),
r = $('#confirm_newpwd');
shaObj.update(p.val());
var p_hash = shaObj.getHash("HEX");
p.val(p_hash);
shaObj.update(q.val());
var q_hash = shaObj.getHash("HEX");
q.val(q_hash);
shaObj.update(r.val());
var r_hash = shaObj.getHash("HEX");
r.val(r_hash);
this.submit()
})
});
So from my limited ability to un-minify my own library, it looks like "c" in this context is probably your input string that you're trying to hash.
Are you fairly certain that p,q, and r all have values that you expect?
Oh man... I just found the problem and this (moment) is embarrassing :P
I forgot to give the fields an id, that's why it's giving the error. It was trying to hash a null value.