B4J Tutorial [ABMaterial] Enabling Users to get their lost passwords via email

Discussion in 'B4J Tutorials' started by Mashiane, May 3, 2017.

  1. Mashiane

    Mashiane Expert Licensed User

    Hi there...

    I wanted users to be able to get their lost passwords via email. This does not reset their passwords but just sends them their passwords to their registered email addresses.

    To enable reseting user passwords by the App administrator, you can see my previous article here. For the app to send the emails, I have used SMTP, you can follow this article here.

    In my Sign In page, in the navigation bar, I have added a link that when selected, will check if the email address is entered, if not prompt a user for one. Once the user email address is entered, the app reads the email account settings that store the SMTP server settings to use, reads the user profile based on the provided email address and then sends the Sign In details for that user.


    Top Nav Bar Items are trapped using the Page_NavigationBarClicked event..

    Sub Page_NavigationbarClicked(Action As String, Value As String)
    If Action = "LogOff" Then
    End If
    Select Case Action.ToLowerCase
    Case "signin"
    Case "forgotpassword"
    Case "goback"
    End Select
        ABMShared.NavigateToPage(ws, ABMPageId, Value)
    End Sub
    This then runs this code..

    Private Sub ForgotPasswordProcess() As Boolean
    'define a map to hold the form contents
        Dim m As Map
    'read the form contents to a map
        m = GetContents
    Dim email As String
    email = m.get("email")
    If email = "null" Then email = ""
    If email.Length = 0 Then
    page,"Email cannot be blank. Please enter a value.")
    Return False
    End If
    'the form contents are ok, send login credentials to user
        'define the search criteria, fields must equal
        Dim w As Map
    Dim nk As String
        nk = 
    'Get connection from current pool if MySQL/MSSQL
        Dim jSQL As SQL = ABMShared.SQLGet
    Dim UserMap As Map = ABMShared.SQLSelectRecordWhereMap(jSQL,"drpw_users", w)
    If UserMap.IsInitialized = False Then
    page,"The Email specified could not be found in our records, please specify the correct email.")
    Return False
    End If
    'The email has been found, send the details to the user
        Dim username As String
        username = UserMap.get(
    Dim password As String
        password = UserMap.get(
    ' start smtp to send the emails
            Dim sbody As String = "Good Day||Someone or you requested your Sign In credentials.||Your UserName is: " & username & "||Your Password is: " & password & "||Development Team|"
            sbody = ABMShared.Replace(sbody,
    smtp,email"DRPW: Sign In Credentials", sbody)
    'Close the connection to the database
    Return True
            myToastId = myToastId + 
    page.ShowToast("toast" & myToastId, "toastred""Email could not be sent, please try again."3000)
    Return False
    End Try
    End Sub
    The code also enables users to Sign In in your app, check and assign their permissions as discussed in this article.

    That's all for now.
    jmon, ihabsharaf, clarionero and 2 others like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice