1

I'm new in javascript. can you help me? I've a js modal popup which loaded whenever user visits my website. in that modal popup I've a login form and I'm trying to login a user through javascript. I've a user.txt file where I've record of users.it doesn't show any error message or page. popup comes again and again

<div class="modal fade" id="myModal" role="dialog">
 <div class="modal-dialog">
   <div class="modal-content">
     <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times</button>
       <h4 style="color:red;"> Login</h4></div>
        <div class="modal-body">
          <form role="form" >
            <div class="form-group">
              <label for="usrname"> Username</label>
              <input type="text" name="username" class="form-control" id="usrname" placeholder="Enter username" required/>
            </div>
            <div class="form-group">
              <label for="psw"> Email</label>
              <input type="email" name="Email" class="form-control" id="email" placeholder="Enter Email" required/>
            </div>
            <span id="loginSpan" style="color:Red"></span>
            <button type="submit" onclick="LoginFunction()" class="btn btn-
        default btn-success  "> Login</button>
          </form>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-default btn-default pull-left" data-dismiss="modal"> Cancel</button>
          <p>Not a member? <a href="#myModal2" data-toggle="modal">Sign Up</</p>   
        </div>
      </div>
    </div>
  </div> 

and my javascript as follow for login

<script> 
 function LoginFunction(){
    var email= $("#email").val();
    var usern= $("#usrname").text();
     var text   = ReadFile();
        var lines   = text.split(";");
         var text    = readFile();
         lines.pop();
         if(email==text[2] && usern==text[1]){
        window.location("index.html");
         }
         else{
         var span=document.getElementById("loginSpan");
         span.text="username or email does not match";
         }
    };
   function ReadFile(){
   var fso = new ActiveXObject("Scripting.FileSystemObject");
    var fh = fso.OpenTextFile("user.txt", 1, false, 0);
       var lines = "";
    while (!fh.AtEndOfStream) {
        lines += fh.ReadLine();
    }
    fh.Close();
    return lines;
    }
</script> 
Muzammil
  • 13
  • 6
  • 1
    saving your userlist into a text file is not recommended btw; from a security stand-point. (you should do this on the backend and limit exposure of user-data to the frontend) – Denis Tsoi Apr 21 '17 at 03:44
  • its my requirement actually – Muzammil Apr 21 '17 at 03:46
  • 1
    Possible duplicate of [Javascript - read local text file](http://stackoverflow.com/questions/14446447/javascript-read-local-text-file) –  Apr 21 '17 at 03:47
  • How can i check my user name or email using this @siddharth. i can't understand it actually – Muzammil Apr 21 '17 at 03:56

0 Answers0