Android Question Offline login

Zizi

Member
Hi there, I am new in B4A just wanted to ask is it possible to create a SQLite database that connects to an Api to retrieve login details (username and password) online and also allow the user to login offline (when not connected to the internet)? if so, can someone please point me to the right direction.
 
Solution
Maybe this is not exactly what you want, but you can check this example.

You can see in the Initialize sub, you check if you have logged previously. Obviously, the first time you log in, you need to be connected to internet.
Not sure if you even want to have a copy of the users and passwords of the online database in a sqlite database to check if the user can log even without internet.

B4X:
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
    jRDC.Initialize
    xui.SetDataFolder("jRDC2Sample")
    KVS.Initialize(xui.DefaultFolder,"kvs") 'We use KVS to save the logged user (Usaremos KVS para guardar el usuario que inicia sesión)

    If KVS.ContainsKey("user") Then  'If we've logged before, go directly to PageData...

Xandoca

Active Member
Licensed User
Longtime User
Hi there, I am new in B4A just wanted to ask is it possible to create a SQLite database that connects to an Api to retrieve login details (username and password) online and also allow the user to login offline (when not connected to the internet)? if so, can someone please point me to the right direction.
Hi,

I understood that you want to create an application that authenticate using an online api, right?
Then login details (user and password) will be stored in SQL Database to be able to login even with no internet connection, right?

is that what you want? if so, you can do it.
 
Upvote 0

Zizi

Member
You mean stay logged in even without Internet? Of course, yes.
You may use SQLite, keyvaluestore or any persistent storage to keep a log in flag.
Hi,

I understood that you want to create an application that authenticate using an online api, right?
Then login details (user and password) will be stored in SQL Database to be able to login even with no internet connection, right?

is that what you want? if so, you can do it.
Yes that is what I meant. Do you know of any source I can refere to, to broaden my understanding, thanx.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Maybe this is not exactly what you want, but you can check this example.

You can see in the Initialize sub, you check if you have logged previously. Obviously, the first time you log in, you need to be connected to internet.
Not sure if you even want to have a copy of the users and passwords of the online database in a sqlite database to check if the user can log even without internet.

B4X:
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
    jRDC.Initialize
    xui.SetDataFolder("jRDC2Sample")
    KVS.Initialize(xui.DefaultFolder,"kvs") 'We use KVS to save the logged user (Usaremos KVS para guardar el usuario que inicia sesión)

    If KVS.ContainsKey("user") Then  'If we've logged before, go directly to PageData (Si hemos iniciado sesión con anterioridad, vamos directamente a la página de datos)
        PageData.Initialize
        B4XPages.AddPage("Page Data", PageData)
        B4XPages.ShowPageAndRemovePreviousPages("Page Data")
        'To avoid loading B4XMainpage if you've logged (check https://www.b4x.com/android/forum/threads/b4xpages-how-to-quickly-load-a-b4xpage-without-showing-mainpage.127180/#post-796199)
        'Para evitar cargar B4XMaipage si hemos iniciado sesión con anterioridad (check https://www.b4x.com/android/forum/threads/b4xpages-how-to-quickly-load-a-b4xpage-without-showing-mainpage.127180/#post-796199)
    End If
End Sub

B4X:
Sub btnLogin_Click
    Toast.Show("Checking user and password...")
    Dim Parametros() As String = Array As String(etUser.Text.Trim, etPass.Text.Trim)
    Wait For(jRDC.GetRecord("Login", Parametros)) Complete (Answer As Map)
    If Answer.Get("Success") Then
        Dim l As List
        Dim rs As DBResult
        rs = Answer.Get("Data")
        l = rs.Rows
        If l.Size > 0 Then 'We get a result
            Dim UserData As List
            For Each row() As Object In l
                UserData = row
            Next
            'Save the user name and id to build the sql queries
            'Guardamos el nombre de usuario y el id para construir las sentencias sql
            KVS.Put("user", etUser.Text.Trim)  'Here you set the flag to save if the user have been previously logged
            KVS.Put("id_user", UserData.Get(0))
            B4XPages.ShowPageAndRemovePreviousPages("Page Data")
        Else
            xui.MsgboxAsync("Wrong username or password", "Error")
        End If
    Else
        xui.MsgboxAsync("Problem connecting: " & Answer.Get("Error"), "Error")
    End If
End Sub
 
Upvote 0
Solution

aeric

Expert
Licensed User
Longtime User
I have an old project for reference, also use KVS at client app.

 
Upvote 0
Top