0

i'm playing with appcreator (https://appcreator24.com) and designing an app from scratch.

I want it to have a "login" screen, where really the only thing that will be used is a password. example: 0101. I am using Bootstrap for layout:

         <form>
          <div class="form-group">
            <label for="exampleInputEmail1"><i class="fa fa-user"></i> Usr</label>
            <input class="form-control" type="text" placeholder="uussrr" readonly>
            <small id="emailHelp" class="form-text text-muted">Same -- all.</small>
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1"><i class="fa fa-key"></i> Contraseña</label>
            <input type="password" id="pswd" class="form-control" id="exampleInputPassword1">
            <input type="checkbox" onclick="myFunction()"> <i class="fa fa-eye"></i> Mostrar
          </div>
          <button style="margin-right: -6px;" type="button" value="Submit" onclick="checkPswd()" class="btn btn-outline-primary"><i style="margin-left: -8px; margin-right: 3px;" class="fa fa-sign-in-alt"></i> Entrar</button>
        </form>

And to check the password:

<script type="text/javascript">
    function checkPswd() {
        var confirmPassword = "0101";
        var password = document.getElementById("pswd").value;
        if (password == confirmPassword) {
             window.location="go:home";
        }
        else{
            alert('Wrong.');
        }
    }
    //Show Password
    function myFunction() {
      var x = document.getElementById("pswd");
      if (x.type === "password") {
        x.type = "text";
      } else {
        x.type = "password";
      }
    }
</script>

I know that it is not the best way to use the password, but it does not matter because it is not an app where you will have a database or sensitive information.

What i want to know is, how can the user "save his ip" so that the application does not ask him to enter the password every time he starts it?

  • You can store that the user is logged in by using localStorage or cookies. –  Sep 07 '20 at 08:06
  • 1
    Does this answer your question? [Persist variables between page loads](https://stackoverflow.com/questions/29986657/persist-variables-between-page-loads) –  Sep 07 '20 at 08:06

2 Answers2

0

The best way would be to save it to localStorage or cookie for a certain device, but if you really want to save password for any device that has the same ip address, then you would want to make a column in your database for ip address, and whenever someone logs in with password, save his ip address with password. On login page load take users ip and check if it's in the database, and if it's not, then make him use password, but if it's saved then let him in.

here is a question how to get ip address in js:

How to get client's IP address using JavaScript?

John Doe
  • 96
  • 7
0

To get the IP address of a user, I usually use the following method. Add this script tag:

<script src="https://api.ipify.org?format=jsonp&callback=getIp"></script>

The source of that script calls the getIp function, with an object containing the IP address of the user passed as a parameter. That means all you have to do to get the address is to create the getIp function:

function getIp(data) {
  var ipAdress = data.ip;
  console.log(ipAdress);
}

Then you can store that address in the localStorage, and log the user in automatically if the IP address is known in your database.

Oskar Zanota
  • 472
  • 3
  • 12