How to create login accounts
Hi, I'm trying to create a program where a user has to login. However, I also want the user to create their own account and login with it whenever they want. For this I have 2 forms (frmLogin and frmCreateLogin).
frmLogin has a username, a password and a login button, aswell as a linklabel connecting it to frmCreateLogin, here is the code for it:
Code:
Public Class frmLogin
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'The purpose is to only allow a User with the right password and username to enter as Admin or Guest
If txtUsername.Text = "Admin" And txtPassword.Text = "4321" Then
'Show Main Menu
frmMemberDetails.Show()
'Hide this form
Me.Hide()
Else : MessageBox.Show("Username or password incorrect. Please try again", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Application.Exit()
End Sub
Private Sub lnkCreate_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkCreate.LinkClicked
frmCreateLogin.Show()
Me.Hide()
End Sub
End Class
frmCreateLogin has 6 fields and 1 button; they are:
Forename
Surname
Username
Password
Re-type password
Authentication password (The admins password, to authorize the creation of the account)
and 'Create Login' button
I haven't added any code to frmCreateLogin because I don't know where to start. Can anyone nudge me in the right direction, as I have no idea how to code this.
Thanks
Re: How to create login accounts
Well, seeing as how you're not using any Databases, and I'm assuming that this is just for the Local Machine. I would suggest you using a Simple Stream Reader/Writer For, Reading and Writing to Files. These files could store your account Information (User/Pass) and can be encrypted using many encryption methods (That is, if you need the security level).
Here's some Sample Code to put you in the Right Direction:
Code:
If My.Computer.FileSystem.FileExists("C:\Accounts.txt") Then 'Checks to see if the file exists.
Dim Input As New IO.StreamReader("C:\Accounts.txt") 'Create a new Stream Reader. This is used to read our file.
MessageBox.Show("Contents: " & vbNewLine & Input.ReadToEnd, "File contents", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Displays the contents of the file.
Input.Close() 'Closes the Stream so it doesn't conflict with Windows. This is IMPORTANT!
Else 'The file does not exist.
Dim Output As New IO.StreamWriter("C:\Accounts.txt") 'Creates a new Stream/File for us to use.
Output.WriteLine("Username: Admin") 'Writes a line to the Text file showing our Username.
Output.WriteLine("Password: 4321") 'Writes another line to the Text file showing our Password.
Output.Close() 'Closes the Stream so it doesn't conflict with Windows. This is IMPORTANT!
MessageBox.Show("Sucessfully Created Account!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Tells the User that the account has been created.
End If
Re: How to create login accounts
good idea by mal1t1a. You could also use a MS ACCESS database if you have that capability. it comes with microsoft office. its a very valuable tool to learn too because you can only do so much with text files...google "ms access vb.net tutorial" if you want to go that path...
Re: How to create login accounts
No I'm quite confused. As you can probably tell, i've just recently started using VB and I don't no where to go from your sample code. I don't no what it means, i've read the comments but i don't understand them, and I don't understand how it links in with my textboxes.
As for the database, I am using SQL but that's on a different form once the user has already logged in (that's probably irrelevant). I wouldn't mind using MS Access, although I only know how to create a connection to MS Access, and once i've done that I don't no what to do.
The code doesn't have to be advanced, or even secure, as long as it succeeds in creating an account for the user.
Thanks for replying
Re: How to create login accounts
ok assuming that you know how to make connections with the ms access,do you know the executenon query() and executereader() ?
if yes then i can give you a sample code that i did a few days before for the same purpose for which you need it.......
reply
Re: How to create login accounts
i saw the code that you put in your 1st post......
An existing user can neither change his password in that code......but it might work if you want the username and password to be fixed...................
i think you should start from the very begining of learning the ado.net fom the msdn.......
Re: How to create login accounts
Nope sorry, but I know a friend who uses access regularly so i could ask him to explain them, so the sample code would be useful..
Or you could just tell me directly what to do, I don't need to understand it, that is bad, but it would get the job done, as my deadline is monday.
1 Attachment(s)
Re: How to create login accounts
Okay, after a couple of Hour's. I have created a Fully working Example for you (and anyone else interested) using the StreamReader and StreamWriter.
It allows you to Create Accounts, and "Login with them". These accounts are stored on the Local Computer, at whatever Location specified (The default is: "C:\Users.txt"). I have Commented on Every-Single Line. I hope this helps you alot.
The example is attached.
[Version 1.1]
I updated the Demo because of a bug with reading the accounts.
[Version 1.2]
Fixed an error with creating the accounts (I forgot to replace vbnewline with vbcrlf).
Re: How to create login accounts
Good Example and generic one :)
Re: How to create login accounts
Looks really good, I cannot tell you how thankful I am, this will help me very much . I'm working on it now and i'll let you know how it goes.
Thanks again
Re: How to create login accounts
ok this may sound really silly but I can't open it for some reason. I can open the files with the code in, but I can't open the resx file, do I need to download a program? And why is there 2 files with code, am I meant to link both of them together? If so how, half the code I don't even understand.
Re: How to create login accounts
Create a new project. Click on the top menu: Project> Add Exisiting File> Then browse to the LoginFormDemo.vb
It'll add itself, then you can do whatever with it. Also, you are very welcome.
Re: How to create login accounts
Ok when I create an account it says the account was not created..? how do i create an account?
Re: How to create login accounts
If you Read that code region, you would find that I said. If there was an error during the account creation process, it would return false. Meaning that it could not be created. If you want, you can debug by putting Msgbox(ex.Message) in this spot:
Code:
try
'code
catch ex as exception
msgbox(ex.message)
return false
end try