get value from HtmlInputElement and check with user pass

33 Views Asked by At

i want to get this value and check with exist user password:

const Users =[{
  userName: 'Hasan1934',
      password: 'Qwx32dksa'
}]

and Input value : const UserName = document.getElementById("username-field") const Password = document.getElementById("password-field") and condition :

 for (let index = 0; index < Users.length; index++) {
            let ArrayItem = Users[index];
            if (UserName === ArrayItem.userName && Password === arrayItem.password ) {
                // console.log("your in !!!!!!!!!!!**********");
                break;}}

it dosent work for me const UserNameHtml = (document.getElementById("username-field") as HTMLInputElement).value

1

There are 1 best solutions below

0
Subhasish Biswasray On

Try this

const Users =[{
   userName: 'Hasan1934',
   password: 'Qwx32dksa'
}]

function isUserExist() {
   const UserName = document.getElementById("username-field");
   const Password = document.getElementById("password-field");
   return !!Users.find(u=>u.userName===UserName.value &&u.password===Password.value);
}
isUserExist();