Search code examples
authenticationapp-inventor

How to code a log-in page in App Inventor 2


Using App Inventor 2, how do you make a log-in service in which I can save a specific Username and Password combination into the app database, so that when people use the app and input a Username and Password combination it is compared to the Username and Password that is saved in the database.

And if they are correct then they are moved onto another page and if they are wrong then they are asked to try again.

Here is a screenshot what I have attempted so far, but it isn't working

enter image description here


Solution

  • You have a lot of problems with that code. First, a problem with your TinyDB. You store the value but you never call it. Second, I wouldn't recommend a TinyDB unless the value of username and password will change. Below is how to make a username and password without a TinyDB .

    Without a TinyDB:

    1. Drag in when button clicked
    2. Drag in an if inside that when button clicked
    3. Drag in an and statement
    4. Drag in two "logic ='s" to each side of the and statement
    5. In one of the equals set the username.text = "(your username)" but use it as a string using the pink string choice that is an empty " "
    6. Repeat step 5 with the password
    7. Click on the blue box on the left of the if and drag in an else. This will only happen if the password and username are wrong.