banner



How To Validate Login Form In C# Windows Application

INTRODUCTION

I have designed a login form in Visual Studio 2015 using Windows Course Awarding with C# code, wherein the username and password become validated at the entry level and would deny entry for users who have unauthenticated credentials. The objective is to be more than precise for the user with his/her username and password created by the ambassador and hence, could non be changed under any circumstance without prior permission from the administrator. Too, to overcome numerous attempts, the validation stops the user from not more than than iii attempts. If all 3 attempts are proven wrong, access is denied for the user and he/she has to communicate with the ambassador for login. To brand the login grade more than creative, I take added motion-picture show box which would display moving-picture show for login and whether access has been granted or not for that particular user. It tin can exist altered with the user photo to await more attractive whenever he/she logs into the application.

Prerequisites

         1. Visual Studio 2015

         2. Arrangement configuration with Windows 8.1 or Windows x

Steps to create a login page.

Pace 1

Open Visual Studio 2015, navigate to File >> New, and choose Projection to open a new projection.

Step 2

After completing Stride 1, a new window opens up with templates for which the application tin can exist chosen. The login class is developed using Visual C# and selecting the corresponding Windows Forms Application. The selected piece of work area could exist saved in this stage by giving desired course proper name in Proper noun text surface area. The form proper name and the solution name volition be the same that the user types. Later completing this, click OK.

Step 3

Windows Form creates a work infinite by displaying an empty form. The user tin select Toolbox from left-top corner to bring the desired tools required for designing. I accept brought the following tools inside my form - label (four nos), textbox (2 nos), button (2 nos), and picturebox (1). Picturebox is included in login grade to add creativity and it displays the corresponding pictures for users who will exist logging into the system.


Step 4

Next stage is for converting the tools brought within the form into meaningful interactives. Tools are named co-ordinate to their usage by correct clicking on whatever tool and then selecting Properties. This displays a window on right side of the screen. Select Text option and blazon the tool name. Label 4 is left empty to display the validating message which is inside the coding.

Step 5

In the Solution Explorer, select Form1.cs which is the work space for our cosmos. Start to code inside the Principal method. This is my code in which I accept included how the tools will be reacting when the project is run.

  1. using  Organisation;
  2. using  Organisation.Collections.Generic;
  3. using  System.ComponentModel;
  4. using  Organization.Data;
  5. using  System.Drawing;
  6. using  System.Linq;
  7. using  System.Text;
  8. using  Arrangement.Threading.Tasks;
  9. using  System.Windows.Forms;
  10. namespace  login_form
  11. {
  12. public  partial class  Form1 : Form
  13.     {
  14. static int  attempt = 3;
  15. public  Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19. private void  button2_Click( object  sender, EventArgs e)
  20.         {
  21. this .Close();
  22.         }
  23. private void  button1_Click( object  sender, EventArgs due east)
  24.         {
  25. string  username = textBox1.Text;
  26. string  countersign = textBox2.Text;
  27. if  (( this .textBox1.Text == "Admin" ) && ( this .textBox2.Text == "admin" ))
  28.             {
  29.                 try = 0;
  30.                 pictureBox1.Prototype =new  Bitmap(@ "C:\Users\Mic 18\Desktop\granted.jpg" );
  31.                 MessageBox.Show("you are granted with access" );
  32.             }
  33. else if  ((endeavor == three) && (try > 0))
  34.             {
  35.                 pictureBox1.Image =new  Bitmap(@ "C:\Users\Mic xviii\Desktop\images1.jpg" );
  36.                 label4.Text = ("You lot Have Only "  + Convert.ToString(endeavor) + " Attempt Left To Try" );
  37.                 --attempt;
  38.             }
  39. else
  40.             {
  41.                 pictureBox1.Prototype =new  Bitmap(@ "C:\Users\Mic 18\Desktop\denied.jpg" );
  42.                 MessageBox.Show("you are not granted with access" );
  43.             }
  44.           }
  45.     }
  46. }

Step 6The completed class looks like this and it is now running. To commencement the application, press F5. The user who uses this form will type the username and desired password to enter into the next level.

Step 7

By typing the correct username and countersign and clicking the LOGIN push button, the picture box changes the default film with a different picture and a message box is prompted telling about the code validation so that the user tin can start accessing the application further.


Step eightIf the user types wrong username or password, the label nether picture box displays a bulletin with the number of attempts left out for the user to try.

Stride 9I have limited the user entry with only three attempts. The code checks for the correct entry in username and password. If all the 3 attempts contain either incorrect username or wrong password, the user volition not be allowed to continue his/her process with the application. This is shown in the below picture show.

SummaryIn the higher up steps, I have explained how to create a elementary login grade using C# in Windows Form Application and validating the username and password with limited attempts likewise as changing the pictures according to the type of user. I have explained a scenario with just one user login. Future enhancements will be including a database with usernames and passwords where we can add together whatever number of users and corresponding passwords.

Source: https://www.c-sharpcorner.com/article/creating-login-form-with-authentication-for/

Posted by: williamshisenturning.blogspot.com

0 Response to "How To Validate Login Form In C# Windows Application"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel