Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For 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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 14th, 2007, 07:19 PM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default login and password

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..

Reply With Quote
  #2 (permalink)  
Old June 14th, 2007, 09:10 PM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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...
Reply With Quote
  #3 (permalink)  
Old June 15th, 2007, 01:42 AM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Airjaws,

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?
Reply With Quote
  #4 (permalink)  
Old June 15th, 2007, 09:18 AM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

p.s. i corrected code
Reply With Quote
  #5 (permalink)  
Old June 15th, 2007, 10:03 AM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #6 (permalink)  
Old June 15th, 2007, 10:20 AM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can give me an example of such select statement pls?

Reply With Quote
  #7 (permalink)  
Old June 15th, 2007, 10:35 AM
Authorized User
 
Join Date: Feb 2004
Location: , CT, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Read my last post. Good luck with your project.

Reply With Quote
  #8 (permalink)  
Old June 15th, 2007, 11:26 AM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i don't get it:D

ok if i had table like this?:

  id name login password
---------------------------------
    1 John johnny tiger
    2 Sam picolovac pica
Reply With Quote
  #9 (permalink)  
Old June 15th, 2007, 05:43 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,105
Thanks: 1
Thanked 63 Times in 63 Posts
Send a message via AIM to dparsons
Default

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)

UserTable
UserID Password Role_FK
---------------------------
4218 foo 1
4219 superfoo 2

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.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Reply With Quote
  #10 (permalink)  
Old June 15th, 2007, 07:52 PM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok ,but i dont see username in tables...

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
login and password airjaws Visual Basic 2005 Basics 5 June 18th, 2007 09:22 PM
Login Controls and Recover Password ~Bean~ ASP.NET 2.0 Professional 12 November 15th, 2006 02:13 PM
Login/Password Java application larry Apache Tomcat 2 December 20th, 2005 03:42 AM
Login with username and password morpheus Classic ASP Basics 4 November 19th, 2003 10:54 AM



All times are GMT -4. The time now is 01:05 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.