2 Replies - 1887 Views - Last Post: 09 November 2009 - 06:00 PM Rate Topic: ***** 1 Votes

#1 Guest_D00M*


Reputation:

VB.NET 2 form login system problem

Post icon  Posted 06 November 2009 - 05:46 AM

Hi, I posted this in the tutorial suggestions topic aswell, but I thought it might be faster if I posted it as a standalone topic.

Basically, I am working on a project which requires a login system. Now the system may be simple ans straight forward, but I am looking for discretionary marks and have dont some research on an advanced login system.

I was able to get what I want. A login system with a create account side to it, whereby a folder with users is created. It is working perfectly but I was only able to do this while both login and create account pages were on the same form, either side by side or on different tabs. I however wish to make form 1 have the login, with a create new account button, which will take me to form 2, which will hold the create account GUI. I tried to do that, didnt seem to be much harder, but after creating the account, form 1, the login form, does not find the folder with the account although i seem to have clearly showed it where it is and put in the variables to read it.



here is my code on the login system:


Create Account button - form2(user gets here by clicking create acc button on form1 :

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateAcc.Click
		If My.Computer.FileSystem.DirectoryExists("C:\Accounts\") Then

		Else

			MkDir("C:\Accounts\")

		End If

		If My.Computer.FileSystem.DirectoryExists("C\Accounts\" + txtUserChoice.Text) Then
			MsgBox("Error - Account allready exists")
		Else
			MkDir("C:\Accounts\" + txtUserChoice.Text)
			Dim a As New System.IO.StreamWriter("C\Accounts\" + txtUserChoice.Text + "\Username.txt")
			a.WriteLine(txtUserChoice.Text)
			a.Close()

			Dim b As New System.IO.StreamWriter("C\Accounts\" + txtUserChoice.Text + "\Password.txt")
			b.WriteLine(txtPassChoice.Text)
			b.Close()

			MsgBox("Account Created. You may now login")
			frmLogin.Show()
			Me.Hide()



		End If
	End Sub



and the login button on form 1, which reappears after user presses create button:

 Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
		Try

			Dim sa As String
			Dim sb As String

			Dim a As New System.IO.StreamReader("C:\Accounts\" + txtUsername.Text + "\Username.txt")
			sa = a.ReadLine()
			a.Close()

			Dim b As New System.IO.StreamReader("C:\Accounts\" + txtUsername.Text + "\Password.txt")
			sb = b.ReadLine()
			b.Close()

			If txtUsername.Text = sa.ToString Then
				If txtPassword.Text = sb.ToString Then
					MsgBox("Welcome -" + sa.ToString)

				Else
					MsgBox("Error - Password Incorrect, please try again")

				End If
			Else

				MsgBox("Error - Account does not exist")

			End If




		Catch ex As Exception

			MsgBox("Error - " + ex.Message)


		End Try
	End Sub 




Note that i used the try and catch way, although there was an alternative, but I wish to use the try and catch as we recently touched on it and it would be good if I used it.

Any Help very much appreciated

Is This A Good Question/Topic? 0

Replies To: VB.NET 2 form login system problem

#2 jcremeans11  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 250
  • Joined: 04-October 09

Re: VB.NET 2 form login system problem

Posted 08 November 2009 - 02:29 PM

Try this...
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateAcc.Click
		If My.Computer.FileSystem.DirectoryExists("C:\Accounts\") Then

		Else

			MkDir("C:\Accounts\")

		End If

		If My.Computer.FileSystem.DirectoryExists("C\Accounts\" + txtUserChoice.Text) Then
			MsgBox("Error - Account allready exists")
		Else
			MkDir("C:\Accounts\" + txtUserChoice.Text)
			Static a As New System.IO.StreamWriter("C\Accounts\" + txtUserChoice.Text + "\Username.txt")
			a.WriteLine(txtUserChoice.Text)
			a.visible=false

			Static b As New System.IO.StreamWriter("C\Accounts\" + txtUserChoice.Text + "\Password.txt")
			b.WriteLine(txtPassChoice.Text)
			b.Close()

			MsgBox("Account Created. You may now login")
			frmLogin.Show()
			Me.visible=false



		End If
	End Sub 


 Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
		Try

			Static sa As String
			Static sb As String

			Static a As New System.IO.StreamReader("C:\Accounts\" + txtUsername.Text + "\Username.txt")
			sa = a.ReadLine()
			a.visible=false

			Static b As New System.IO.StreamReader("C:\Accounts\" + txtUsername.Text + "\Password.txt")
			sb = b.ReadLine()
			b.visible=false

			If txtUsername.Text = sa.ToString Then
				If txtPassword.Text = sb.ToString Then
					MsgBox("Welcome -" + sa.ToString)

				Else
					MsgBox("Error - Password Incorrect, please try again")

				End If
			Else

				MsgBox("Error - Account does not exist")

			End If




		Catch ex As Exception

			MsgBox("Error - " + ex.Message)


		End Try
	End Sub

This post has been edited by jcremeans11: 08 November 2009 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_D00M*


Reputation:

Re: VB.NET 2 form login system problem

Posted 09 November 2009 - 06:00 PM

Hmm, there are still some errors coming up when creating the account which didn't happen before, but the main problem of bridging the 2 forms seems to have been resolved :D, Thank you very much. I'm sure I can clean up the rest with a bit of work. Once again, cheers!!

This post has been edited by D00M: 09 November 2009 - 06:01 PM

Was This Post Helpful? 0

Page 1 of 1