Pro Visual Basic 2005For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
ok ive put this post in begining VB 2005 subforum, but im sure ill get here answers faster.
here's the problem:
i need to make login screen to my application, which after u login goes to another form..i need someone to explain me how to check user name and password, and also i have to give users certain rights, for example - u can add new user, or smtng like that...but that goes to other form...
i thought of having table with id, name, surname, login, password and type of right...
base should be in sql, and environment is VB 2005
thnx for help, hope some answers soon..
ok ive got it myself so far, the best thing to do is to do it yourself:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim user As String
Dim pass As String
position = 0
user = txtLogin.Text
pass = txtPass.Text
If user = Me.PiDataSet.nt_osoba.Rows(position).Item("login") And Pass = Me.PiDataSet.nt_osoba.Rows(position).Item("sifra") Then
frmGlavna.Show()
End If
end sub
my next question should be:
it is ok if you have just one record but now i would like that it goes through iteration or such and checks password that you type to work regardless in which row in databse it is. e.g. now it checks only 1st row, because position is 0.
I hope u get what i mean - this now works only if u type password that is in first row, bu i want it to work with that username and password regardless...
I understood your first post fine and you seem to be heading in exactly the right direction. You need a table with username and password, preferably encrypted depending on the requirements of your application. And you need a table where you store the user's rights. Those rights can be in the username/password table if it fits your app architecture.
Upon the user clicking "login" you will do SQL select statement looking for the username, compare (encrypted) password and fetch the rights.
You got all that correct.
Your second post confused the heck out of me. I have no idea what you were getting at. Where did you initialize the dataset and code the SELECT statement? Why are you concerned that there is only one row returned? That seems normal; why would you want to iterate on multiple rows? What would those extra rows contain?
ok ill give example, it will be clearer:
if u have for example 3 users: admin, guest and memebr of some group, i would like that all of them can login with their own login name and password. each one of them has his own rights, but ill manage to do that by making buttons and stuff visible or not on another form...
with the code i did, u have an option to login just with one of these accounts (admin or group member or guest, depending which row i set "position" to) Have you understood?
I don't see that any changes have been made to the code you listed, but no, I still don't understand what your problem is.
Why are you setting position to 0? Are you opening the table and only looking at the first row? Why?
The proper way is not to open the table or use the data control to return the entire set of rows in the table and then iterate through the records, the proper way is to use the dataset to return only the single row you need by coding a SELECT statement ("select * from (table name) WHERE login = " & user) if I understand your code (which I'm not sure I do).
I think you might be better off in the beginner's forum where you can learn the basics of using datasets to return only specific records. You're not going to get help with that here. I'm sure you can get many examples of what you need by a quick search on the web and certainly your "intro to vb.net" book has more than enough info for you to code this part of your project. Good luck.
Hmm. You are confusing yourself. I do the same type of thing every day in all of my applications (the only difference is that their logon is completely transparent to the user) and its not that hard, you are just making it as such!! ;]
Essentially what you are doing is setting up a Role based permission set, user's don't actually have rights to the application, the Role that they belong to has permissions. My table structure is something like this: (I have added a password column to help you with your example)
RoleTable
ID Description
-----------------------
1 Admin
2 Member
3 Guest
Now you could do something like this:
Dim s as String = String.Format("SELECT Role_fk From UserTable where UserName={0} and PassWord={1}", Me.txtUserName.text, Me.txtPassword.text)
//Fill a DataTable/DataSet/DataReader
I will use a DataTable as my example:
If dt.Rows.Count = 0 Then
MessageBox.Show("You provided an Invalid UserName and password!")
Else
Dim iRole as Integer = Convert.ToInt32(dt.Rows(0).Item("Role_FK"))
SELECT CASE iRole
Case 1
'You are an Admin show all controls
Case 2
'You are a User show some controls
Case 3
'You are a guest show no controls
END Select
End If
I think that is very straight forward but let me know if you have any questions.