Search code examples
javascriptpasswordsany

Javascript password - check first letter only


I need a login which only checks the first letter of a password and ignores anything behind of it. Here is the standard login-code I got from my last script. I know Its very not secure for web solutions:

var unArray = ["ExampleTom"];   //User
var pwArray = ["7******];"]     //Password
for (var i=0; i <unArray.length; i++) {
if ((un == unArray[i]) && (pw == pwArray[i])) {
    valid = true;

The idea is that the user should type any number as he wants as a password, but if it starts with a 7 he succeeds (The '7***' is just written to illustrate my idea).


Solution

  • I don't know why would you ever do that but here it is:

    var unArray = ["ExampleTom"];   //User
    var pwArray = ["7******];"]     //Password
    
    valid = false
    
    for (var i=0; i <unArray.length; i++) {
      if ((pwArray[i]. charAt(0) === pw.charAt(0)) && (un == unArray[i])) {
         valid = true;
      }
    }