Create Login Window in C# Using Sql Server

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hi all, in this video tutorial I will show you how to create a login screen in your windows application so let's get started this is my visual studio 2010 so we have to create a Windows application first. Go to file then project otherwise you can use shortcut ctrl+shift+N and under visual c# select windows then windows application choose directory where you want to save this application. Name your application, then click OK. after creating the project the solution Explorer your Windows application will be look like this. there will be a default form Form1 during this case we don't need that, Now we need to add form for login so right click on Windows application then add new item under visual c# items select windows form, name windows form as frmLogin, then click OK. this our login form. Now we need to change some of the properties of this form, for that you have to click right click on the form then properties other ways select the form click F4 change text as login then start position as center screen,set false for maximized box, now we have a form for login, I need to add required controls for login, in this case you have to launch tool box, in my case it is there in the left panel, if you are not able to see tool box, go to view then click toolbox, then drag controls like button, label then text box now we need one more label for that hold ctrl key then drag lable so here we have one copy of this control in the same way we need one more text box and one more, now we need to change properties of this control so go to properties then change text as username then password, name this text box something meaningful txtUsername txtPassword btnLogin change button text as login, last button as Exit btnExist, now we need to arrange these Controls Controls. Changing Control Font to Size 10. now we have our login form now we need one more form, that is main screen. frmMain usually main screen will be big in size form text as dashboard and start position as center screen then ShowIcon to false, window state will be normal so far we have created screens for our windows application now we need to create a database for our application, for that go to view then click on server Explorer right click on that data connections, add connection select a location where you want to save this database name your DB here in my case, it is LoginDB click on open click OK asking for whether you want to save it or not create it or not ? click on yes Go to tables there is no table so now we want to create a table give column names loginid, username varchar(50) password varchar(50) setting LoginID as primary key. To create the table you have to save (the table), for that press Ctrl + S (it will open dialog box).Name the table something like tblLogin click OK in this case I'm going to add few login records directly into our login table loginid 1 username user1 password qwerty loginid 2 username user2 paswword qaz (press enter to save rows) press Ctrl + R to refresh Now we have two login records for user1 and user2 now we have our form design and db here so now we can start coding basically an application start with login screen then after authorizing the user using this username and password if the user is authorized then main screen will be open for him so in our application start form will be our login form so we have to set our start form here by specifying frmLogin so when the application start the login screen logging form will be open for the user so in the in so in this login button click event, we had to check to whether the user is authorized or not for that first of all we need sql connection object, To use SQL connection object you have to import or use system .Data.SqlClient then creating an object of Sql Connection Class sqlcon new SqlConnection @ symbol and within this these two quotes you have to specify the connection string for this DB, right click on the DB go to properties can select this text here and paste here remove these two extra quotes okay so we need to write our query it will be something like this SELECT * FROM tblLogin WHERE username = txt username is the name of textbox.text .trim() to avoid extra white space from the both ends and password = txtpassword.text .trim() so now we have our query here SELECT * FROM tblLogin where username equals text in the textbox for username and password equals the text in the password text box so we need another object of class SQL data adapter sda equals new SQL DataAdapter and pass your query here then SQL connection object creating an objective of DataTable dtbl = new DataTable sda. Fill the dtbl, if a dtbl.Rows.Count equals 1 frm Main objFrmMain = new frmMain() objFrmMain.Show() this.Hide(); else Check your username and password so what we actually do is here we have a query to select user records that satisfies based on the username and password so in this SqlDataAdapter Fill the selected selected rows into this table so after that we will check number of rows in the table if number of rows is equal to 1 there is a user for the given user name and password that must be user1 or user2 and password for user1 must be qwerty and for user2 it must be qaz so if the DataTable contains one row we will open the main screen like this otherwise we pop up a message saying Check your username and password okay in this Exit button click event write code for closing screen so let me start our application started here and going to end an incorrect combination of password and username user100 password qaz Check your username and password user1 qwerty as password click login main screen main form will be opened that means username and password is valid so that's it you can do one more thing for password text box to hide the password set password character here * mark or something else as you wish, when you enter password it will shown like sequence of * marks so that's it I hope you enjoyed this video and download this project from the link given below in video description please be subscribe to my channel for more have a nice day bye
Info
Channel: CodAffection
Views: 483,569
Rating: undefined out of 5
Keywords: login window in c#, how to create login window in c#, how to make login screen in C# sql server, login window in c# step by step tutorial, in visual studio 2010, sql server authentication in login screen, with user authentication, login form with sql database, login form check user autentication, c# login form design, login and logout in c#, login system in c#, login app in winform, in sql server 2008/2012/2014/2016, user authentication in c#, yt:cc=on, CodAffection
Id: NX8-LhgFnUU
Channel Id: undefined
Length: 19min 20sec (1160 seconds)
Published: Sat Feb 27 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.