Results 1 to 13 of 13

Thread: How to Store Username and Password

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: How to Store Username and Password

    the best way to do this is to store the usernames and passwords into a database, then connect your vb6 app to the database. there are many threads on this already.

  2. #2
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to Store Username and Password

    You can create a database from Microsoft Access. Put two fields like "username" and "password".


    Put this to your module

    VB Code:
    1. Option Explicit
    2. Public cn As ADODB.Connection
    3.  
    4.  
    5. 'connection string from Microsoft Access
    6. Public Sub OpenConnection()
    7.  
    8. Set cn = New ADODB.Connection
    9. With cn
    10.     .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\yourdbase.mdb;Persist Security Info=False"
    11.     .CommandTimeout = 0
    12.     .CursorLocation = adUseClient
    13.     .Open
    14. End With
    15. End Sub


    Put this to your form

    VB Code:
    1. Public rs As ADODB.Recordset
    2.  
    3.  
    4. Private Sub Form_Load()
    5.     OpenConnection
    6. End Sub
    7.  
    8. Private Sub Command1_Click()
    9. Set rs = New ADODB.Recordset
    10.  
    11.    strsearch = "SELECT username FROM tablename WHERE username like '" & Text1.Text & "'"
    12.     rs.Open strsearch, adoc, adOpenDynamic, adLockOptimistic
    13.     rs.Requery
    14.  
    15.    If rs.RecordCount >= 1 Then
    16.       'put your conditions here
    17.    else
    18.       'your code here
    19.    end if
    20.  
    21.  
    22. End Sub

    This is just a sample. you can find much better codes out here.

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    8

    Re: How to Store Username and Password

    Thanks for the great info but i dont have microsoft access so it doesnt help me much. i also dont know how to link the two programs together to get the database from one to the other. if it is possible i would like to have the vb program self-contained. i would like the username and password saved all within the vb program.

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How to Store Username and Password

    Quote Originally Posted by wryan_garner4
    i would like the username and password saved all within the vb program.
    I'm not sure what you mean by that ?

    And about the link I posted, that example is using Access, but you can easily change it to whatever database you want. Just change the Connection String in the LoadDatabase function, and the SQL statements to match the database SQL type... though I think the SQL statements should be the same in any database...

    Just remember that if the example is made for Access, it does not mean that this works ONLY in Access...

  6. #6
    Member
    Join Date
    Nov 2006
    Location
    Jerusalem
    Posts
    39

    Re: How to Store Username and Password

    the data entered in the user name and password fields must be linked to a database so you can retrieve them later for validation.. add an adodc control and cofigure connection settings.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: How to Store Username and Password

    You don't need to store them in a database although there's noting wrong with that. Another good way is to store the data in the Registry. If you store it there you should encrypt the password and also possibly the username.

  8. #8
    New Member
    Join Date
    Nov 2006
    Posts
    2

    Re: How to Store Username and Password

    Quote Originally Posted by wryan_garner4
    Thanks for the great info but i dont have microsoft access so it doesnt help me much. i also dont know how to link the two programs together to get the database from one to the other. if it is possible i would like to have the vb program self-contained. i would like the username and password saved all within the vb program.
    I understand what you mean. You need to be very careful doing this, because anyone can trivially read the username and password back out of the file. However, if you need to store this, you can use a CRC32 hash to obfuscate the password. What you would do is generate a CRC32 hash of the password ahead of time, and store that in a module. At runtime, DON'T compare password to password, but rather hash the password that the user types in, and compare that to your stored hash.

    It's not foolproof, in that specially crafted strings can generate the same CRC32, but it's significantly more complex to reverse engineer.

  9. #9
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How to Store Username and Password

    Quote Originally Posted by insta
    I understand what you mean. You need to be very careful doing this, because anyone can trivially read the username and password back out of the file. However, if you need to store this, you can use a CRC32 hash to obfuscate the password. What you would do is generate a CRC32 hash of the password ahead of time, and store that in a module. At runtime, DON'T compare password to password, but rather hash the password that the user types in, and compare that to your stored hash.

    It's not foolproof, in that specially crafted strings can generate the same CRC32, but it's significantly more complex to reverse engineer.
    That is exacly what I posted in Post #4, except I'm using MD5 to hash wich is 128 Bit

  10. #10
    New Member
    Join Date
    Nov 2006
    Posts
    2

    Re: How to Store Username and Password

    Quote Originally Posted by CVMichael
    That is exacly what I posted in Post #4, except I'm using MD5 to hash wich is 128 Bit
    Apologies ... I was trying to provide a database-less solution. Although I guess I didn't actually include any code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width