-
Making Login Restriction
Hi guy's i am using vb6 and sql server 2000 and i create my login form and already connected to the sql i am wondering how to make some restriction on login. Sample when i login Admin i can access everything in form2 but when i login kobe some buttons or textbox i can't access. How could i do that? Need a big help guy's :D
-
Re: Making Login Restriction
Define a Global Boolean variable in your module and set them to true when there is an admin login and set them to false when user logs in. Depending upon that variable enable/disable you buttons/text box :)
-
Re: Making Login Restriction
Quote:
Originally Posted by
koolsid
Define a Global Boolean variable in your module and set them to true when there is an admin login and set them to false when user logs in. Depending upon that variable enable/disable you buttons/text box :)
How to do that sir? I have no idea sorry for that :o
-
Re: Making Login Restriction
I suggest setting up database roles for access and check those instead of hardcoding IDs.
-
1 Attachment(s)
Re: Making Login Restriction
Hi...
Check the example attached....:wave:
-
Re: Making Login Restriction
It's more work and some research but if this is an application of any substance and will reside in a commercial production environment learn to use DB roles versus hardcoding IDs as in the example by akhileshbc. If it is something small and just controled by you the example is fine.
-
Re: Making Login Restriction
@TysonLPrice: Can you give me a small example description regarding DB roles ?
Thanks..:wave:
-
Re: Making Login Restriction
Quote:
Originally Posted by
akhileshbc
Hi...
Check the example attached....:wave:
Thank's for the info sir but what if my user and password are stored in my datatabase and not on my form. How to restrict it? Same as you do?
-
1 Attachment(s)
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
How to do that sir? I have no idea sorry for that :o
Ok. Here is a very basic example. Amend it as per your requirements :)
-
Re: Making Login Restriction
It is generally more beneficial to post ZIP files. RAR support isn't available in Windows and many users don't see a reason to pay for and install it.
-
Re: Making Login Restriction
Quote:
Originally Posted by
koolsid
Ok. Here is a very basic example. Amend it as per your requirements :)
inside the list box i will get it the content on the sql?
-
Re: Making Login Restriction
Quote:
Originally Posted by
akhileshbc
@TysonLPrice: Can you give me a small example description regarding DB roles ?
Thanks..:wave:
Got to work right now :D
I'll get back to you...
-
Re: Making Login Restriction
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
Thank's for the info sir but what if my user and password are stored in my datatabase and not on my form. How to restrict it? Same as you do?
In the login form, try the username and password checking using data from your database. Then, assign the user role based on that user. :wave:
@TysonLPrice: That's ok. I'll wait :)
-
Re: Making Login Restriction
Quote:
Originally Posted by
akhileshbc
In the login form, try the username and password checking using data from your database. Then, assign the user role based on that user. :wave:
@TysonLPrice: That's ok. I'll wait :)
I cant get what you say sir please clarify me what to do. sorry for that :(
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
I cant get what you say sir please clarify me what to do. sorry for that :(
It will be something like this (for example):
Code:
Option Explicit
Private Sub cmdOK_Click()
'~~~ Add reference to Microsoft ActiveX Data Objects 2.x Library
'~~~ We are going to check the database for the entered username and password. You need to make the necessary changes to suit your needs
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & App.Path & "\database.mdb;Persist Security Info=False;Jet OLEDB:Database Password=myDBpassword;"
cn.Open
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM all_users WHERE user_name = '" & Trim$(txtUserName.Text) & "' AND password = '" & txtPassword.Text & "'", cn, adOpenForwardOnly, adLockReadOnly
If rs.EOF = False Then
Select Case LCase$(txtUserName.Text)
Case "admin"
myUser = user_Admin
Form1.Show
Unload frmLogin
Exit Sub
Case "guest"
myUser = user_Guest
Form1.Show
Unload frmLogin
Exit Sub
Case "normal"
myUser = user_Normal
Form1.Show
Unload frmLogin
Exit Sub
End Select
End If
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End Sub
You need to read the articles and tutorials in our Database Development FAQ section to know more about database manipulation.
Good luck...:thumb:
-
Re: Making Login Restriction
why your getting this?
Code:
Code:
"Data Source= " & App.Path & "\database.mdb;Persist Security Info=False;Jet OLEDB:Database Password=myDBpassword;"
-
Re: Making Login Restriction
Quote:
Originally Posted by
dilettante
It is generally more beneficial to post ZIP files. RAR support isn't available in Windows and many users don't see a reason to pay for and install it.
Dilettante
I agree.
Spoo
-
Re: Making Login Restriction
@dilettante: Uploaded a .Zip file :)
-
Re: Making Login Restriction
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
why your getting this?
Code:
Code:
"Data Source= " & App.Path & "\database.mdb;Persist Security Info=False;Jet OLEDB:Database Password=myDBpassword;"
Read the articles in here: http://www.vbforums.com/showthread.php?t=337051#ado, particularly this tutorial: http://www.vbforums.com/showthread.php?t=551154...:wave:
-
Re: Making Login Restriction
Your using there a MS Access right?
-
Re: Making Login Restriction
vb Code:
Private Sub cmbUser_Click()
If cmbUser.ListCount = 0 Then Exit Sub
Me.cmdDatabaseFiles.Enabled = True
Me.cmdFilesDatabase.Enabled = True
Me.cmdChkProfile.Enabled = True
End Sub
Private Sub getUser()
On Error GoTo ErrHandler
set_rec_getData "SELECT username FROM tblUser", rs, cn
Do While Not rs.EOF
Me.cmbUser.AddItem Trim$(rs("username"))
rs.MoveNext
Loop
If cmbUser.ListCount <> 0 Then cmbUser.ListIndex = 0
rs.Close
Set rs = Nothing
Exit Sub
ErrHandler:
MsgBox "Error: " & Err.Description & vbNewLine & "Error Number: " & Err.Number, vbCritical
End Sub
I am using this codes to show the values in combo box but when i run it nothing happens i did not get anything to the database.
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
Your using there a MS Access right?
Yes..:)
Quote:
Originally Posted by
bloodsside14
I am using this codes to show the values in combo box but when i run it nothing happens i did not get anything to the database.
Then, you have to provide us more details for checking that issue. Like the sub that deals with the database (set_rec_getData) and other things.
....:wave:
-
Re: Making Login Restriction
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
i don't have any sub sir
Ok. Where's the connection ? Have you dealt with database before ?
Does it show any errors ? Did you checked your database - i mean, does it have any records ?
-
Re: Making Login Restriction
there is a record there for sure and set a primary key. Not showing any errors, run smoothly but no records in combo box.
-
Re: Making Login Restriction
Now i can connect to my datatabse using this codes
vb Code:
Dim rs As New ADODB.Recordset
If Trim(Combo1.Text) <> "" And Trim(txtpass.Text) <> "" Then
If cnn.State <> adStateOpen Then cnn.Open
rs.CursorLocation = adUseClient
rs.Open "SELECT * FROM tblUser WHERE username='" & Trim(Combo1.Text) & "' AND password='" & Trim(txtpass.Text) & "'", cnn, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
Combo1.Enabled = False
txtpass.Enabled = False
Label1.Enabled = False
Label2.Enabled = False
cmdOK.Enabled = False
cmdCancel.Enabled = False
Form2.Show
Form1.Hide
Else
MsgBox "The username and password that you provided" & vbCrLf & "are not found in the database.", vbApplicationModal + vbInformation, _
"Invalid Admin"
Combo1.Text = ""
txtpass.Text = ""
Combo1.SetFocus
End If
rs.Close
Set rs = Nothing
cnn.Close
Else
MsgBox "Required admin details are missing.", vbApplicationModal + vbExclamation, "Missing Information"
Combo1.SetFocus
End If
End Sub
and this is my connection to dbase
vb Code:
Option Explicit
Public cnn As New ADODB.Connection
Public strConnection As String
Public strAccess As String
strConnection = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MIAA;Data Source=PAULO\MONTEALEGRE"
cnn.ConnectionString = strConnection
cnn.Open
Dim rs As New ADODB.Recordset
If cnn.State <> adStateOpen Then cnn.Open
rs.Open "SELECT username FROM tblUser", cnn, adOpenStatic, adLockReadOnly
If Not rs.EOF Then
Do While Not rs.EOF
Combo1.AddItem Trim(rs!username)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End If
The only thing i need is to put an restriction how to connect it to my dbase the code that you give.
vb Code:
If Len(Trim(Combo1.Text)) = 0 Or Len(Trim(Text1.Text)) = 0 Then
MsgBox "Please select username and enter the password"
Exit Sub
End If
strUser = Combo1.Text
Select Case strUser
Case "Administrator"
If Text1.Text = "1" Then
boolAdmin = True
Form2.Show
Unload Me
End If
Case "User1"
If Text1.Text = "2" Then
Form2.Show
Unload Me
End If
End Select
End Sub
Public boolAdmin As Boolean
Public strUser As String
-
Re: Making Login Restriction
Use this as your user name (using a text box) and anything for the password:
' or 1=1 ---
Then have a look here http://articles.sitepoint.com/articl...n-attacks-safe
Your safe because of you combo box but since you are looking at log on procedures you should be aware of injection attacks if you are not already.
-
Re: Making Login Restriction
i am doing my user as a combo box. getting the user name in database.
-
Re: Making Login Restriction
Quote:
Originally Posted by
bloodsside14
i am doing my user as a combo box. getting the user name in database.
Try this as your password:
' or 1=1 or 1 = '