![]() |
|
[.NET] Basic Login System [TuT] - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Basic Login System [TuT] (/showthread.php?tid=1695288) |
Basic Login System [TuT] - Lenneth - Sep 5, 2011 Hello HackForumers! This is my next tutorial on how to make a basic login system with a nice little feature for registering users! I saw a few members requesting this in other topics so I thought I would just share this. It was done as a school project (Just to get us used to VB.NET) earlier on in the year. A lot of this was done by myself as I loved to get ahead and do my own features so enjoy the tutorial! Okay so first we should always design our GUIs! Make it look the best to your own standards, don't bother caring with what other people think (Unless it was really bland..) So here is my version of my GUI. ![]() Okay so what we need in our form is these: 3 x Forms 3 x Buttons 2 x Labels Pretty basic isn't it? This is the simple version of what we have. You can name these anything you like however I've decided to name mine: Forms: Login.vb & Success.vb & Register.vb Buttons: btnLogin & btnReg & btnClose Labels: txtName & txtPass Alright so onto our coding. This isn't too hard if you know about objRead. Code Dim filename As String = "E:\Login_Program\Login\login.txt" We need to declare these variables in our btnLogin (Or Button1). Declaring filename is just using it for objRead which is just reading the text file for the login as well as it locates the file. (It's easier this way since we just use filename from now on in the button). Next we need to declare intError which if an error of 1 happens to appear, then an error will show. Lastly we declare objRead as a StreamReader with of coarse, our declared filename! This is so we don't have to type in the filepath every time. Next we need to be able to read the text file as well as create a loop so it reads through the text file not just one or two lines! Code Do While objRead.Peek() <> -1Now we need to add an if statement for our validation process. This is so if we have the incorrect details then we won't login! We simply start off like this: Code If txtName.Text = objRead.ReadLine() And txtPword.Text = objRead.ReadLine() ThenCode Me.Hide() Now we need to finish off our loop so we know that it'll read throughout the whole text file. We simply add this code after it: Code LoopCode If intError = 1 Then 'If an error has occured'Lastly we need to close the objRead so the program doesn't infinite loop and eventually crash! We do this by adding: Code End IfAlso add for your register button: Code Me.Hide()This is so we can do our next part of registering new users! Now that was the first form out of two for coding (The third is only just a welcome screen which I couldn't be bothered using). If the login details are correct then my Success form will show like so: Now it's time for coding the register details for the program! First we should design the register form, so mine looks like this: ![]() I simply have: 2 x Buttons 3 x Labels 3 x Textboxes (You can name these yourselves as you should have the simple knowledge on using these!) This is because I added a little validation, if the two passwords aren't the same, then the program returns an error. You don't have to have this added but it'll be added into this source. So go click on your register form and lets get started. First we need to declare two more variables: Code Dim filename As String = "login.txt" This is for our register button on the register form, so we need to add the validation sequence and if it's correct then objWrite will write the username and password to the text file, like so in the code below: Code If txtPass.Text = txtRPass.Text ThenCode If txtUser.Text = "" And txtPass.Text = "" ThenCode objWrite.Close()Code ElseAdd a message box to let the user that the account is created just for personal use! Code MessageBox.Show("The new account has been created!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)Code ElseCode End IfThe program seems pretty simple, doesn't it? Hints and Tips: Try declaring the declarations above the the buttons just under Form1. This'll let it know that they're Global (So they can be used all over the form, not just where they're specified). Try it out yourself and let me know how this program is. Code Dim filename As String = "file.txt"Thanks again! My program will be added here later.. But there isn't much to it. Happy Coding! -Lenneth * - NinjaxDGx - Sep 5, 2011 There are better methods but good tut if it was not a copy paste :) * - Lenneth - Sep 5, 2011 (Sep 5, 2011 05:45 PM)NinjaxDGx Wrote: There are better methods but good tut if it was not a copy paste :) Like I said, basic. And don't assume it's a copy paste as that is my program, not letting people download the source. I hate copy/pasting, took me nearly an hour to write this up.. While Im still at school hehe. * - deiski - Sep 5, 2011 (Sep 5, 2011 06:16 PM)Lenneth Wrote: Like I said, basic. OMG, Quote:While Im still at school hehe. How did you get so skillfull? Can you teach me your coolness? I didn't make VB.net Programs sitting at school while the teacher wasn't looking. You tank. * - Lenneth - Sep 5, 2011 (Sep 5, 2011 06:54 PM)Cyan Wrote: OMG, How.. Hurtful? Flame all you want, I gave what users wanted. If you don't have any criticism involved then why not bother elsewhere :) * - Coleak - Sep 5, 2011 What the hell? Why would you save it on E drive??? * - Chuck Norris . - Sep 6, 2011 90% HF users are still at school dear and some of them make more money than your parents does. * - Lenneth - Sep 6, 2011 (Sep 5, 2011 11:27 PM)Coleak Wrote: What the hell? Why would you save it on E drive??? Where my USB is located, however I forgot to drop it in the 'bin' folder. * - The Unknown - Sep 6, 2011 Lenneth you did a good job but this can be SO easily cracked lol * - Lenneth - Sep 6, 2011 (Sep 6, 2011 12:53 AM)The Unknown Wrote: Lenneth you did a good job but this can be SO easily cracked lol Encryption is what I'll sometime learn soon however users who make this can experiment for themselves. |