B4J Code Snippet Login Example

Here is a small example of a login screen that if successful will load the main form. Might not be perfect. But is a good start for someone. Uses a MySQL database.
 

Attachments

  • LoginExample.zip
    7.1 KB · Views: 754

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, thanks for sharing.

I think this is the worst aproach for making a login, because you are requesting the actual password from the database. This is really unsafe, and it can be sniffed ot of the network.

Instead of:
B4X:
Dim RS As ResultSet = MySQL.SQLCon.ExecQuery("SELECT * FROM users WHERE T_username = '" & UserNameToCheck & "';")

Its easier and safer something like this:

B4X:
Dim RS As ResultSet = MySQL.SQLCon.ExecQuery("SELECT * FROM users WHERE T_username = '" & UserNameToCheck & "' AND T_password = '" & PasswordToCheck & "';")

If you get no records, the password and/or the username are wrong.

Also consider avoiding storing passwords as plain text. you can use a hash function to store them.
 
Top