create login problem !

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gillian3114
    New Member
    • Mar 2007
    • 16

    create login problem !

    i got 3 type username and password :
    1. boss
    2. manager
    3. staff

    how should i check if the username is exist then pop up msgbox error else add username and password to database


    Code:
    Dim rss As New ADODB.Recordset
    Dim strID As String
    Dim cnn As New ADODB.Connection
    Dim strCNString As String
    Dim intFound As Integer
    
    strCNString = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
    cnn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
    cnn.ConnectionString = strCNString
    cnn.Open
    
    If txtPassword.Text <> txtC_Password.Text Then
        MsgBox "Password must be same with confirm pasword ! ", vbExclamation, "Error"
    Else
        With rss
            .Open "SELECT emp_id, s_username,s_password, m_username,m_password, b_username,b_password FROM Employees", cnn, adOpenDynamic, adLockOptimistic
             Do Until .EOF
                If txtSearch.Text = !emp_id Then
                    If txtUserName.Text = !s_username Then
                    intFounds = 2
                        MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
                    Else
                      If txtType.Text = "boss" Then
                        !b_username = txtUserName.Text
                        !b_password = txtPassword.Text
                        .Update
                        MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                        txtSearch.Text = ""
                        txtName.Text = ""
                        txtType.Text = ""
                        txtUserName.Text = ""
                        txtPassword.Text = ""
                        txtC_Password.Text = ""
                        intFounds = 1
                        
                      ElseIf txtType.Text = "manager" Then
                        !m_username = txtUserName.Text
                        !m_password = txtPassword.Text
                        .Update
                        MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                        txtSearch.Text = ""
                        txtName.Text = ""
                        txtType.Text = ""
                        txtUserName.Text = ""
                        txtPassword.Text = ""
                        txtC_Password.Text = ""
                        intFounds = 1
                        
                      ElseIf txtType.Text = "staff" Then
                        !s_username = txtUserName.Text
                        !s_password = txtPassword.Text
                        .Update
                        MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                        txtSearch.Text = ""
                        txtName.Text = ""
                        txtType.Text = ""
                        txtUserName.Text = ""
                        txtPassword.Text = ""
                        txtC_Password.Text = ""
                        intFounds = 1
                        
                      End If
                End If
                      
                End If
                .MoveNext
              Loop
              .MoveFirst
              If intFounds = 0 Then
                       MsgBox "Employee ID not found !", vbExclamation, "Search"
              ElseIf intFounds = 2 Then
                        MsgBox "Please change username and try againt !", vbExclamation, "Error"
                        txtUserName.Text = ""
                        txtPassword.Text = ""
                        txtC_Password.Text = ""
              End If
    
         End With
         Exit Sub
    
    cnn.Close
    End If
    cnn.Close
  • gillian3114
    New Member
    • Mar 2007
    • 16

    #2
    how about if wan check m_username and b_username at the same time

    Code:
    ' why this cant work ?
          If txtUserName.Text = !s_username and txtUserName.Text = !m_username and txtUserName.Text = !b_username Then
    
              intFounds = 2
              MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      dear there is one procedure
      u've to folloe that
      first check user name then password if login and pwd is correct then check its privilages
      follow this flow
      Good Luck

      Comment

      • ansumansahu
        New Member
        • Mar 2007
        • 149

        #4
        Originally posted by gillian3114
        i got 3 type username and password :
        1. boss
        2. manager
        3. staff

        how should i check if the username is exist then pop up msgbox error else add username and password to database


        Code:
        Dim rss As New ADODB.Recordset
        Dim strID As String
        Dim cnn As New ADODB.Connection
        Dim strCNString As String
        Dim intFound As Integer
        
        strCNString = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
        cnn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
        cnn.ConnectionString = strCNString
        cnn.Open
        
        If txtPassword.Text <> txtC_Password.Text Then
            MsgBox "Password must be same with confirm pasword ! ", vbExclamation, "Error"
        Else
            With rss
                .Open "SELECT emp_id, s_username,s_password, m_username,m_password, b_username,b_password FROM Employees", cnn, adOpenDynamic, adLockOptimistic
                 Do Until .EOF
                    If txtSearch.Text = !emp_id Then
                        If txtUserName.Text = !s_username Then
                        intFounds = 2
                            MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
                        Else
                          If txtType.Text = "boss" Then
                            !b_username = txtUserName.Text
                            !b_password = txtPassword.Text
                            .Update
                            MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                            txtSearch.Text = ""
                            txtName.Text = ""
                            txtType.Text = ""
                            txtUserName.Text = ""
                            txtPassword.Text = ""
                            txtC_Password.Text = ""
                            intFounds = 1
                            
                          ElseIf txtType.Text = "manager" Then
                            !m_username = txtUserName.Text
                            !m_password = txtPassword.Text
                            .Update
                            MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                            txtSearch.Text = ""
                            txtName.Text = ""
                            txtType.Text = ""
                            txtUserName.Text = ""
                            txtPassword.Text = ""
                            txtC_Password.Text = ""
                            intFounds = 1
                            
                          ElseIf txtType.Text = "staff" Then
                            !s_username = txtUserName.Text
                            !s_password = txtPassword.Text
                            .Update
                            MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
                            txtSearch.Text = ""
                            txtName.Text = ""
                            txtType.Text = ""
                            txtUserName.Text = ""
                            txtPassword.Text = ""
                            txtC_Password.Text = ""
                            intFounds = 1
                            
                          End If
                    End If
                          
                    End If
                    .MoveNext
                  Loop
                  .MoveFirst
                  If intFounds = 0 Then
                           MsgBox "Employee ID not found !", vbExclamation, "Search"
                  ElseIf intFounds = 2 Then
                            MsgBox "Please change username and try againt !", vbExclamation, "Error"
                            txtUserName.Text = ""
                            txtPassword.Text = ""
                            txtC_Password.Text = ""
                  End If
        
             End With
             Exit Sub
        
        cnn.Close
        End If
        cnn.Close
        Hi ,

        You will have to decide the order in which you want to check the User Name and the password combination. Check for one type of user if it does not exist then move on to the next tyoe and so one. Does your Login screen allow the liberty to the user to select a User Type before they do the Login.

        thanks
        ansuman sahu

        Comment

        Working...