login as admin , HOW !?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 4
Reputation: eng.N is an unknown quantity at this point 
Solved Threads: 0
eng.N eng.N is offline Offline
Newbie Poster

login as admin , HOW !?

 
0
  #1
Oct 15th, 2008
hi ,

I'm using VB.net :
I want to create login and check if the user is admin or not from the table in the database .

in my database i have table(Log_in) contains : user name , Password , User Type .


I create Login Form :

  1. Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
  2.  
  3. Dim vCon As New SqlConnection
  4. vCon.ConnectionString = "..... "
  5. Dim vSelectCommand As New SqlCommand
  6.  
  7.  
  8. Dim myCommand As SqlCommand
  9. myCommand = New SqlCommand("SELECT [User_Name],[Password],[User_Type] FROM Log_in WHERE [User_Name] = @UserName AND [Password] = @UserPassword AND [User_Type] = @UserType", vCon)
  10.  
  11. Dim uName As New SqlParameter("@UserName", SqlDbType.NVarChar)
  12. Dim uPassword As New SqlParameter("@UserPassword", SqlDbType.NVarChar)
  13. Dim uType As New SqlParameter("@UserType", SqlDbType.NVarChar)
  14.  
  15.  
  16.  
  17.  
  18.  
  19. uName.Value = UsernameTextBox.Text
  20. uPassword.Value = PasswordTextBox.Text
  21.  
  22. "uType.Value = "admin
  23.  
  24.  
  25.  
  26.  
  27.  
  28. myCommand.Parameters.Add(uName)
  29. myCommand.Parameters.Add(uPassword)
  30. myCommand.Parameters.Add(uType)
  31.  
  32. myCommand.Connection.Open()
  33.  
  34.  
  35.  
  36. Dim myReader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
  37.  
  38. Dim Login As Object = 0
  39.  
  40. If myReader.HasRows Then
  41. myReader.Read()
  42. Login = myReader(Login)
  43. End If
  44.  
  45. If Login = Nothing Then
  46. MessageBox.Show("sorry ....")
  47. Else
  48.  
  49.  
  50. ' Administrator Roles :
  51.  
  52. If uType.Value = "admin" Then
  53.  
  54. myCommand.Parameters.Add(uType)
  55. MessageBox.Show("User identified as Admin, logging in")
  56.  
  57. Form1.Show()
  58. Form1.SystemToolStripMenuItem.Enabled = True
  59. Form1.ReportToolStripMenuItem.Enabled = True
  60. Else
  61.  
  62. If uType.Value = "user" Then
  63. myCommand.Parameters.Add(uType)
  64. MessageBox.Show("Login successful")
  65. Form1.Show()
  66. Form1.SystemToolStripMenuItem.Enabled = False
  67. Form1.ReportToolStripMenuItem.Enabled = False
  68.  
  69. End If
  70.  
  71.  
  72.  
  73.  
  74. End If
  75.  
  76. '............
  77.  
  78.  
  79. Me.Hide()
  80.  
  81.  
  82. End If
  83.  
  84. End Sub


...

The Problem is the user Type its only work correctly with admin ,

Could you help me , please ?
Last edited by cscgal; Oct 15th, 2008 at 11:26 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: login as admin , HOW !?

 
0
  #2
Oct 16th, 2008
"SELECT [User_Name],[Password],[User_Type] FROM Log_in WHERE [User_Name] = @UserName AND [Password] = @UserPassword " and then check which User_Type this user has. I won't correct the rest of your code, you can surely do it yourself.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 4
Reputation: eng.N is an unknown quantity at this point 
Solved Threads: 0
eng.N eng.N is offline Offline
Newbie Poster

Re: login as admin , HOW !?

 
0
  #3
Oct 19th, 2008
acually I don't know how to complete the code , where should I declare the user type ?!


could you write the code , please ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC