How to Create Login Page in Asp.Net With Sql DataBase

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to god that mob in this video we will learn how to create a login page in asp.net web application so let get started let me create a fresh asp.net web application for that go to file then new and project select asp.net empty web application name your application here in my case I will name it as asp.net login page then select the location where you want to save the application then click on OK so here we have our brand new SP dotnet web application now let me add a verb form for loading page for that right-click on the project then add web form namely web form as login click on OK so here we need to design our login page for that I will use a table tag inside that first row first row will be 0 for entering user name and each consists of two corns one for lab and one for textbox and let me open the tool box and then I am going to drag one label and then one text box into the second column let me copy the row I am facing below that so I pasted the road two times so first row will be for entering user name so first level will be user name then the textbox ID will be txt username and second level will be password and corresponding text box will be txt password the last row will be used for the login button in that case first column will be empty in the second column we need a button for logging let me drag the button and it's ID will be BTN login and text will be logging finally I would like to add a row for displaying error when you say ending correct a user name or password so I will use a label to show the error message and its ID will be lb error error message and text will be incorrect user credentials now I need to add a style for this tab so that I can use style attribute equals margin as quarto in order to Center the table then I'm going to add a border for this table 5px solid then white color and I need to add background color for the enter login page body background color as which let me switch to design mode log in page design looks fine now but we need to make this level foreground color to red let me shoot back to a source for color equals red that's it now I am going to add a button click event for this button for that right click on it then go to properties and here you can see a lightning symbol click on it then double click on this click so that it will create a button click even in the background so here is the button click event for the login button in order to work with a login and logout system we need to have a database with use a table so let's create one visit table now let me open my management studio say we have a database logging DB inside that we are going to create a new table for that right click on tables then click on table first column will be user ID and data type will be IND and then second forum username as well 50 then password will be work 250 and then I am going to set this user ID as the primary key for the table and in order to save the table you can use the shortcut control s or you can click on this same button here it will open dialog box like this here you can enter the table name TBL user click on OK in order to see the newly created average click on tables then click on this refresh button here you can see the newly created user table right click on it and edit top 20 was now I am going to add few tests force into this table user ID will be 1 then username has user 1 so it will be one two three in order to save this rose plus end up that's it now back to visual studio first of all we need to use this namespace a system dot that or the SKU our client and a system dot data in order to work with SQL Server database here we have our login form design during user authentication we will check is there any user with given username and password if there is a user with given username and password we will show him the dashboard otherwise we show this incorrect user credential message so now let's do that first of all I will hide this error message during the page load so it can be done like this LBL error message dot visible equals false now inside this login button click event we will check whether the user name and password is valid or not for that you can do something like this you see then SQL connection an object of SQL con is created new SQL connection inside that we need to provide the connection string and it will be something like this that our source because local backward slash SQL e 2012 then semicolon initial catalog equals DB name log in DB then semicolon then integrated security to true then SME part then inside the using block we will write the query string query because select count one from TBL user were username equals activate username and password equals add the red password that's it so here we have used parametrized query if you're going to concatenate the direct string from our username and password text box there is a chance for SQL injection so I used parametrized query here and here I have provided the connection string if you found any problem or to follow this connection string I have done another video tutorial on how to connect SQL database from c-sharp I have put the video link in video description please go through that and next we are going to create an object of SQL comment SQL CM d equals new SQL comments then first parameter will be V query query then connection object SQL corn and that's it then we need to pass the or parameter or values for that parameters dot add which value then we need to pass two parameter value one for username and one for password let me copy the parameter name from here and pushing here same for password and then here we need to pass the txt username text finally I will use the trim function we use trim function to avoid are white white spaces from both sides of this string saving the case of password instead of username we use txt password that's it and we want to declare a variable count it was convert to in 32 to inside that I will execute this particular command SQL command don't execute scale-out so here inside this count variable we will get the number of users with given username and password if count is equal to 1 it means there is a user with given username and password so user authentication is successful so we can check like this if count equal to 1 user is valid so let me save the user details inside session session with key user name equals txg username dot X dot 3 so session is a dictionary inside asp.net web application we can use these sessions to store values session is created to each logged in users so each user has separate session finally we will show him the dashboard page for that we can call the function response dot redirect as a parameter we need to pass the page name dashboard dot aspx now we need to create a page for dashboard for that right click on the application then add webform M your form has dashboard and click on OK so we have created our dashboard page now back to loading page if count not equal to 1 maybe show him the error message LBL error message dot visible equal true now we have created a loading page in our SP dotnet web application now let me run the application for that click on this start button here now let me try to login with there in Carlos of M and password SD and password STS actually we need to make these textbooks as our ask dots for that you can change the design like this go to source then text mode sequence spatulas now let me try to log in click on this loading button here this is error in our connection string you need to change that into integrated security integrated security so here we need to open this connection SQL corn door open let me run the application again let me post in cut password and username finally it shows the interactive circuit inches now let me try to log in with the correct username and password so it will be user one password will be one two three click on this login button so now it shows the dashboard page now inside this dashboard page I will implement logout button for that back to vicious view then this our dashboard page let me drag one level then a line break for that I will put a break here then a button this label will be named as lbn user details texts will be empty then I will name this button SBT and log out with text log out let me switch to design mode right click on this logo button then properties click on events double click on this click and then inside the page load event he will set the user details in our level like this user name equals so we have saved the session here that inside this key we have saved the user details or user name and we will retrieve that here you can do that like this let me go PD session so inside this session we will have the logged in user name and in the bottom click event in order to log out a user we just need to call the function session tour abandoned it will clear all the session values and then we will redirect the user to a login page now let me run the application again the surname will be user 1 password 1 2 3 click on this login button now we are in dashboard ok you can see the loading user details username as you saw on if you click on this logout button we will be logged out from the website let me click on this now we log out from our application now we have to do one more thing now I actually am logged out if I want to open the dashboard page you can directly type the you all right here - bot dot SPX it will open the dashboard page without any error you can see that there is no user login and in order to avoid this we can do something like this back to visual studio then inside the dashboard page to open the application here we need to check whether user is logged in or not for that we can use this session session if there is a value inside this user name it means there is a user if it is null it means there is no user so we will redirect the user to a login page response dot redirect redirect to login dot s3x let me run the application again I am trying to open the dashboard page for that I will type the direct you are here and so here you can see bad we are redirected back to login page that's it guys in this video we have discussed how to create logging page in asp.net with SQL Server database we have discussed all the aspects of the top so finally we have a complete login and logout system in asp.net application you can download this project with SQL server script from the link given below in video description that's for today please do subscribe to my channel dotnet mob for more our some videos like this please like and share this video with your friends and colleagues so that they can benefit from this have a nice day bye
Info
Channel: CodAffection
Views: 199,983
Rating: 4.8246245 out of 5
Keywords: How to Create Login Page in asp.net using sql database, Login Page in asp.net application, Complete Login and Logout System in asp.net, login page in asp.net web form, create login page in asp.net using session, user authentication in asp.net, asp.net tutorial for beginners, login page in asp.net using c# using sql server database, how to create login page in asp.net with database using c#, asp.net mvc login page using database c#, asp.net login page using database c#, CodAffection
Id: F7mmzhFXugM
Channel Id: undefined
Length: 19min 46sec (1186 seconds)
Published: Tue Apr 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.