I'm building a web application and need to built a login site. How do I loop through this javascript object and compare the user input on the login form (only email ("EML") needed at the moment) to the data to make sure the input is correct? I tried to make something, but only came up with the for loop below that is just a mess. (The object is in a seperate js file) Thank you!
function validate() {
var un = document.login.username.value;
var pw = document.login.password.value;
var valid = false;
for (var key in responseData) {
if (responseData.hasOwnProperty(key)) {
for (var i = 0; i < key.length; i++) {
if (un == key[i]) {
valid = true;
break;
}
}
}
if (valid) {
alert("Login was successful. Welcome, " + un + ".")
window.location = "https://www.google.com";
return false;
}
}
var responseData = {
authenticatUser: {
"ERR":0,
"RSP":{
"AUTHC":"true",
"USR":{
"ID":"2",
"TJT":"FULL",
"ACTV":"true",
"BO":"1489760664786",
"CONT":{
"FNM":"John",
"LNM":"Doe",
"PHN":"5556667777",
"PHNTP":"NONE",
"EML":"ex@mple.com",
"EMLTP":"NONE"
},
"ADMIN":"false",
"LLOGN":"1489760664786",
"ACCT":{
"ID":"2",
"TJT":"ID"
}
}
}
},
getUserAccountDetails: {
"ERR":0,
"RSP":{
"ACCT":{
"ID":"2",
"TJT":"FULL",
"ACTV":"true",
"BO":"1489760664786",
"LU":"1489760664786",
"NM":"Name",
"DESC":"Description",
"CONT":{
"FNM":"John",
"LNM":"Doe",
"PHN":"5556667777",
"PHNTP":"NONE",
"EML":"ex@mple.com",
"EMLTP":"NONE"
},
"ADDRM":{
"STRT":"1 Miracle Way",
"CITY":"San Antonio",
"STATE":"Texas",
"ZIP":"78245"
},
"ADDRB":{
"STRT":"1 Miracle Way",
"CITY":"San Antonio",
"STATE":"Texas",
"ZIP":"78245"
},
"TZ":"US_CT",
"LICS":"1",
"REPOS":[
{
"ID":"2",
"TJT":"ID"
},
{
}
],
"USRS":[
{
"ID":"2",
"TJT":"ID"
},
{
}
]
}
}
}
};