Hello. I looked on the site and didnt seem to find anything on this so hopefully you havnt allready touched on it and Im just being ignorant. It is a simple matter anyway but I am very new to VB and would appreciate the help.
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.
I am getting long-winded here so I will post the code I curently have setup, and will ask if you could possibly make a tutorial on how to create an advanced login system on 2 forms as I have described. Thanks
here is my code on the login system:
Create Account button - form2(user gets here by clicking create acc button on form1 :
CODE
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:
CODE
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.
This post has been edited by D00M: 5 Nov, 2009 - 07:35 AM