Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Help: Creating VB text based game log in screen

Help: Creating VB text based game log in screen

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasegame-devdata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jblouir
    wrote on last edited by
    #1

    I am developing a VB.NET text based adventure and I need help with coding a log in button. Basically I have a table called tblUserAccounts This table as 3 fields... accountID username Password The log in screen form has a combo box for username and a text box for password with a button just to the right that says Log in. What I want to happen is that when the person clicks log in after they enter there information into the combo box and text box, that (insert code here) will basically take their username and password(that they entered) and search for it in the database and if it exists in the database allow them to log in. OR Alternatively I could make array variables that are = to the table columns(from the database) username and password, then I can perform my own checks in the VB.Net code itself on the button click. for example I tried doing this... Dim arrUsername() As Array = GameprojectDatabase.tblUserAccounts.UserColumn but I get the message that it can not be converted to a 1-dimensional array If anyone can explain to me how I can do this please let me know.

    D 1 Reply Last reply
    0
    • J jblouir

      I am developing a VB.NET text based adventure and I need help with coding a log in button. Basically I have a table called tblUserAccounts This table as 3 fields... accountID username Password The log in screen form has a combo box for username and a text box for password with a button just to the right that says Log in. What I want to happen is that when the person clicks log in after they enter there information into the combo box and text box, that (insert code here) will basically take their username and password(that they entered) and search for it in the database and if it exists in the database allow them to log in. OR Alternatively I could make array variables that are = to the table columns(from the database) username and password, then I can perform my own checks in the VB.Net code itself on the button click. for example I tried doing this... Dim arrUsername() As Array = GameprojectDatabase.tblUserAccounts.UserColumn but I get the message that it can not be converted to a 1-dimensional array If anyone can explain to me how I can do this please let me know.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      This would be easy enough with an SQL query to your Access database:

      SELECT COUNT(Username) FROM Users WHERE Username=?Username And Password=?Password
      

      This is, of course, ignoring all security concerns and assumes that all the passwords are stored unencrypted. All you would have to do is create an OleDbConnection to the database, an OleDbCommand object to execute the query, a couple of OleDbParameter objects, added to the Parameters collection of the OleDbCommand object, with the username and password values filled in, and then call the ExecuteScalar method of the command object. The number returned by that call will tell you how many username/password records matched the inputs. It SHOULD be 1 or 0. If 0, then the login failed. If 1, it worked. If MORE than 1, you've got a consistancy problem with your data as there are more than 1 record in the table with the same username and password.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        This would be easy enough with an SQL query to your Access database:

        SELECT COUNT(Username) FROM Users WHERE Username=?Username And Password=?Password
        

        This is, of course, ignoring all security concerns and assumes that all the passwords are stored unencrypted. All you would have to do is create an OleDbConnection to the database, an OleDbCommand object to execute the query, a couple of OleDbParameter objects, added to the Parameters collection of the OleDbCommand object, with the username and password values filled in, and then call the ExecuteScalar method of the command object. The number returned by that call will tell you how many username/password records matched the inputs. It SHOULD be 1 or 0. If 0, then the login failed. If 1, it worked. If MORE than 1, you've got a consistancy problem with your data as there are more than 1 record in the table with the same username and password.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        J Offline
        J Offline
        jblouir
        wrote on last edited by
        #3

        Thank you :-)...Now if I only knew how to do that lol. I read stuff like this elsewhere but have not found anywhere that explains it clearly. Looking through help files is like trying to find a needle in a haystack, and not only that the needle your looking for has hundreds of twins that confuse the heck out of you.

        D 1 Reply Last reply
        0
        • J jblouir

          Thank you :-)...Now if I only knew how to do that lol. I read stuff like this elsewhere but have not found anywhere that explains it clearly. Looking through help files is like trying to find a needle in a haystack, and not only that the needle your looking for has hundreds of twins that confuse the heck out of you.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          I'm sure you've seen something like this:

          Public Function AttemptLogin(ByVal Username As String, ByVal Password As String) As Boolean
          Dim queryString As String = "SELECT COUNT(Username) FROM User WHERE Username=?Username AND Password=?Password"
          Dim result As Integer = 0
          Using connection As New OleDbConnection(connectionString)
          Dim command As New OleDbCommand(queryString, connection)
          command.Parameters.Add(New OleDbParameters("?Username", OleDbType.VarChar, 15)).Value = "someusername"
          command.Parameters.Add(New OleDbParameters("?Password", OleDbType.VarChar, 15)).Value = "somepassword"

              connection.Open()
              result = command.ExecuteScalar()
              connection.Close()
          
              Return (result=1)
          End Using
          

          End Function

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups