By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,099 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,099 IT Pros & Developers. It's quick & easy.

create login problem !

P: 16
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


Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim rss As New ADODB.Recordset
  3. Dim strID As String
  4. Dim cnn As New ADODB.Connection
  5. Dim strCNString As String
  6. Dim intFound As Integer
  7.  
  8. strCNString = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
  9. cnn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
  10. cnn.ConnectionString = strCNString
  11. cnn.Open
  12.  
  13. If txtPassword.Text <> txtC_Password.Text Then
  14.     MsgBox "Password must be same with confirm pasword ! ", vbExclamation, "Error"
  15. Else
  16.     With rss
  17.         .Open "SELECT emp_id, s_username,s_password, m_username,m_password, b_username,b_password FROM Employees", cnn, adOpenDynamic, adLockOptimistic
  18.          Do Until .EOF
  19.             If txtSearch.Text = !emp_id Then
  20.                 If txtUserName.Text = !s_username Then
  21.                 intFounds = 2
  22.                     MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
  23.                 Else
  24.                   If txtType.Text = "boss" Then
  25.                     !b_username = txtUserName.Text
  26.                     !b_password = txtPassword.Text
  27.                     .Update
  28.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  29.                     txtSearch.Text = ""
  30.                     txtName.Text = ""
  31.                     txtType.Text = ""
  32.                     txtUserName.Text = ""
  33.                     txtPassword.Text = ""
  34.                     txtC_Password.Text = ""
  35.                     intFounds = 1
  36.  
  37.                   ElseIf txtType.Text = "manager" Then
  38.                     !m_username = txtUserName.Text
  39.                     !m_password = txtPassword.Text
  40.                     .Update
  41.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  42.                     txtSearch.Text = ""
  43.                     txtName.Text = ""
  44.                     txtType.Text = ""
  45.                     txtUserName.Text = ""
  46.                     txtPassword.Text = ""
  47.                     txtC_Password.Text = ""
  48.                     intFounds = 1
  49.  
  50.                   ElseIf txtType.Text = "staff" Then
  51.                     !s_username = txtUserName.Text
  52.                     !s_password = txtPassword.Text
  53.                     .Update
  54.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  55.                     txtSearch.Text = ""
  56.                     txtName.Text = ""
  57.                     txtType.Text = ""
  58.                     txtUserName.Text = ""
  59.                     txtPassword.Text = ""
  60.                     txtC_Password.Text = ""
  61.                     intFounds = 1
  62.  
  63.                   End If
  64.             End If
  65.  
  66.             End If
  67.             .MoveNext
  68.           Loop
  69.           .MoveFirst
  70.           If intFounds = 0 Then
  71.                    MsgBox "Employee ID not found !", vbExclamation, "Search"
  72.           ElseIf intFounds = 2 Then
  73.                     MsgBox "Please change username and try againt !", vbExclamation, "Error"
  74.                     txtUserName.Text = ""
  75.                     txtPassword.Text = ""
  76.                     txtC_Password.Text = ""
  77.           End If
  78.  
  79.      End With
  80.      Exit Sub
  81.  
  82. cnn.Close
  83. End If
  84. cnn.Close
  85.  
  86.  
Apr 5 '07 #1
Share this Question
Share on Google+
3 Replies


P: 16
how about if wan check m_username and b_username at the same time

Expand|Select|Wrap|Line Numbers
  1.  
  2. ' why this cant work ?
  3.       If txtUserName.Text = !s_username and txtUserName.Text = !m_username and txtUserName.Text = !b_username Then
  4.  
  5.           intFounds = 2
  6.           MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
  7.  
  8.  
Apr 5 '07 #2

vijaydiwakar
100+
P: 579
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
Apr 5 '07 #3

100+
P: 149
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


Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim rss As New ADODB.Recordset
  3. Dim strID As String
  4. Dim cnn As New ADODB.Connection
  5. Dim strCNString As String
  6. Dim intFound As Integer
  7.  
  8. strCNString = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
  9. cnn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
  10. cnn.ConnectionString = strCNString
  11. cnn.Open
  12.  
  13. If txtPassword.Text <> txtC_Password.Text Then
  14.     MsgBox "Password must be same with confirm pasword ! ", vbExclamation, "Error"
  15. Else
  16.     With rss
  17.         .Open "SELECT emp_id, s_username,s_password, m_username,m_password, b_username,b_password FROM Employees", cnn, adOpenDynamic, adLockOptimistic
  18.          Do Until .EOF
  19.             If txtSearch.Text = !emp_id Then
  20.                 If txtUserName.Text = !s_username Then
  21.                 intFounds = 2
  22.                     MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
  23.                 Else
  24.                   If txtType.Text = "boss" Then
  25.                     !b_username = txtUserName.Text
  26.                     !b_password = txtPassword.Text
  27.                     .Update
  28.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  29.                     txtSearch.Text = ""
  30.                     txtName.Text = ""
  31.                     txtType.Text = ""
  32.                     txtUserName.Text = ""
  33.                     txtPassword.Text = ""
  34.                     txtC_Password.Text = ""
  35.                     intFounds = 1
  36.  
  37.                   ElseIf txtType.Text = "manager" Then
  38.                     !m_username = txtUserName.Text
  39.                     !m_password = txtPassword.Text
  40.                     .Update
  41.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  42.                     txtSearch.Text = ""
  43.                     txtName.Text = ""
  44.                     txtType.Text = ""
  45.                     txtUserName.Text = ""
  46.                     txtPassword.Text = ""
  47.                     txtC_Password.Text = ""
  48.                     intFounds = 1
  49.  
  50.                   ElseIf txtType.Text = "staff" Then
  51.                     !s_username = txtUserName.Text
  52.                     !s_password = txtPassword.Text
  53.                     .Update
  54.                     MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
  55.                     txtSearch.Text = ""
  56.                     txtName.Text = ""
  57.                     txtType.Text = ""
  58.                     txtUserName.Text = ""
  59.                     txtPassword.Text = ""
  60.                     txtC_Password.Text = ""
  61.                     intFounds = 1
  62.  
  63.                   End If
  64.             End If
  65.  
  66.             End If
  67.             .MoveNext
  68.           Loop
  69.           .MoveFirst
  70.           If intFounds = 0 Then
  71.                    MsgBox "Employee ID not found !", vbExclamation, "Search"
  72.           ElseIf intFounds = 2 Then
  73.                     MsgBox "Please change username and try againt !", vbExclamation, "Error"
  74.                     txtUserName.Text = ""
  75.                     txtPassword.Text = ""
  76.                     txtC_Password.Text = ""
  77.           End If
  78.  
  79.      End With
  80.      Exit Sub
  81.  
  82. cnn.Close
  83. End If
  84. cnn.Close
  85.  
  86.  
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
Apr 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.