Help with login through mobile app

gordon

Member
Licensed User
Longtime User
In theory yes, but I would caution against saving sensitive information that can be read by anyone who has access to the device simply by booting the app. Adapting the code by thedesolatesoul in the link you provided you could make use of the third possible response of the dialog box and do something like this

B4X:
 'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
login
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub login
    Dim username As String
    username=getusername
    Dim Id As InputDialog
    Dim p As Panel 
    Dim etun As EditText 
    Dim etpw As EditText 
    Dim lblun As Label 
    Dim lblpw As Label
   
    
    p.Initialize("")
    etun.Initialize("etun")
    etpw.Initialize("etpw")
    lblun.Initialize("")
    lblpw.Initialize("")
   
    etun.SingleLine = True
    etpw.SingleLine = True
    etpw.PasswordMode=True
    
    Dim cd As CustomDialog 
    
    cd.AddView(p,2dip,0,90%x-4dip,220dip)
    p.AddView(etun,40dip,80dip,p.Width-80dip,48dip)
    p.AddView(etpw,40dip,150dip,p.Width-80dip,48dip)
    p.AddView(lblun,40dip,60dip,p.Width-80dip,40dip)
    p.AddView(lblpw,40dip,130dip,p.Width-80dip,40dip)


    p.Color=Colors.Black 
    etun.Hint="Username"
    etpw.Hint="Password"
    lblun.Text="Username"
    lblpw.Text="Password"
      etun.Text=username
    cd.Show("XverhelstX Login","Login","Cancel","Login & Save username",Null)
    lblun.RequestFocus 

    If cd.Response = DialogResponse.CANCEL Then
        'Cancel stuff
        Return
   Else If      cd.Response=DialogResponse.NEGATIVE Then
         
         saveusername
         Msgbox("Your user name has bee saved","User Name Saved")
      Else
      'authenticate
         Msgbox("Log in no save","User name not saved")
   End If
  
    'Authenticate
   
End Sub

Sub saveusername

'authenticate user 
'there is no value in saving a user that does not pass authentification
'if authenticate user =true then
   'save user name to text file
'else
   'failed authenticate
'end if

End Sub

Sub getusername() As String
   'username = read file where username is stored
   Dim use As String
   use="Only Me!" 'in live app var  use would   = the contents of the text file
   Return use
End Sub

But my feelings are that it is something that that should be avoided.
 
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
I appreciate your feedback and will definitely look into alternative ways to use the login prompt.
 
Upvote 0
Top