Creating Login Form | C Sharp | C# | Visual Studio | with and without database validation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends you are welcome in this video tutorial i'm just teach you like how to create a login form using visual studio using c shop language here we learn a login form with database and also without database without database is easy because we add code in a coding what is the user id and password that we need to compare and we need to get the result whereas in case of database validation so the program should connect to the database and there it should check the user id and password and here is a login form example it will have two text boxes one for the user id so this is for the user id the other one for password password so both the values matches then only should log in otherwise you shouldn't log in so for that you supposed to use visual studio in case if you don't have visual studio you can download the visual studio from microsoft website so in order to download visual studio you have to go to microsoft website so here you can download community editions or you can go to free uh even it's okay free visual studio or you can download the community community is a free edition so and if after download you need to install when you're installing you need to select visual basic in case you would like to work on visual basic projects and c-sharp in case you would like to work for the c-sharp project and particularly there again web project or desktop project so you need to install all the options which are the options you required so we have a separate video for that please follow that and now i'll start visual studio and i'll show you like how to create a login page in visual studio so already installed in my system so therefore i'll just go to visual studio 2019 right so let me start from the scratch so when you start this this is a welcome screen we have so if you already have some projects you'll show the recent projects okay so then eventually if you would like to create a new project here you can see that there is a new project so click on the create new project so when you click new project you need to select a c-sharp project for desktop therefore you just browse over here right so windows form application.net framework and this is a c shop language this is for windows and this is the desktop application so here is option a project for creating application with windows forms user interface okay so let me create the windows forms interface so i'll choose this one and click next option so because we are using c-sharp language therefore we are making desktop application therefore you select this option so click next next is the project name so what is the project name would like to give so let me say login project c sharp because you are using c sharp i'll just give us a c sharp over there next is a location where you would like to save this project okay so by default we'll go to the user's default folder but i don't want over here so therefore we browse here so there is a browse button then maybe you check it out where you would like to save maybe d drive is ideal you select this one in my case i'll select this temp directory then i'll go to projects so here i would like to create the project so therefore i select new projects and now so login project c shop is the folder name and the project name both in case you are creating in your system you make a go to d drive create your name and then c sharp projects create a prop folder cut a c sub project and under that you can save this one fine next is the framework so we have multiple frameworks over here so present i'm using 4.6 even you can use ir version there is no problem the next is you click the create button fine now you can see that it created a project login project c and here is a solution explorer you can see what are the components by default you already have you have one dot program dot cs file uh here basically it shows like from which form you want to start in the beginning okay so therefore we have only one form so therefore you say application dot run new form one so therefore it will run the form one and here is the form one so this is the form one and you would like to see the code so you go to the code section so it is a code window so when you click by default uh this much code is already there so you whenever you want to write new code based on the event we can write the code for this right so let me run the project so here is a start button you click the run so the project will run because you have only one form that particular form will run let's see that how the form looks like fine so here is the form so this is what how it's running okay so first step i'll do is let me change the color okay let me change the background color so to change the background color so go to back color you need to select the form then go to properties window so assume in case you don't have the properties window over here so what you can do is go to view menu and choose properties window so here is a properties window so you need to select the properties window so then you will get the properties window in a properties window you need to select back color so therefore to change the back color go to back color then click and go to custom colors and choose the color you want so we also separate videos to learn c sharp so go through them so learn step by step then you'll these things you can learn much more faster right so now next step is now i'm going to run the project so you see that that is in the purple color right so next step is you want to make it this window or this form to be big sizer complete window size so in order to make this you have a property called as windows state so select the windows state and select maximized select maximized and see that it should go to the full screen now the form will go for full screen right so next you want to change the title here that is the form one instead of form 1 we want to say login form so in order to do this there is a text property so we need to change the text property so here it is form 1 text so then change the text property to login form so the login form right so that change to login form now so we have a login form next step is we need to design the login form so we require two text boxes and the two buttons and two labels so now to get them so you have to go to toolbox again in case you don't have the toolbox over here you go to view menu and then select the toolbox here so here is a tool box we need to click on the toolbox to get back the toolbox right so here is a toolbox so we have all the form controls let me close that tag and we will take only common controls in a common controls we required text box therefore i'll select the text box here and i'll draw it on the page or form right one text box then i want label so therefore let me take label the label then i want one button so i'll just take the button here so button then drag it on the screen now we have three one is the text box label button and see that the point size is very small so let me increase the point size we can increase the point size selecting the one one control or else if you form level if you increase the point size then automatically link this to every control therefore i select the form so you can see that form is selected here and then go to point by default it is around eight point so therefore we want eight we will let me make it twelve and here point is concerned let me select verdana so this is vardana and click ok now you can see that text boxes increases the size is increased because now the point size is 12 whatever you enter the point will be 12 now so it's a label now move the label over there here and give the caption or you change the text to user id or login id login id then let me decrease the size here okay now again we required two more um sorry one more label one more text box what i'll do is i click somewhere outside and drag it here i want to select both the controls so if i leave this means how i do this so move the cursor somewhere on the right left top click lift the so press the left mouse press the left key button so then drag it so then both the controls are selected now we can copy right click copy then click somewhere outside and then right click and then paste so you can see that the controls are pasted again now you can see the name okay so now this is a text box too the pre one is text box one when you copy and paste the control number automatically get increases so it is a login id so instead of login id let me make it as a password so here is a password right so then button for button text so we want to make it as a login here so therefore i just go to text here and then give the name as a login i required one more button to cancel this if i don't want to log in i want to close the application so paste it here so then here you can say cancel right so now our design is ready so we have two labels two text boxes two buttons so i cannot change any names control names all default names only these are text box one text box to button one and then button two so now first let's see how to write a code without database right so first i'll run the project so start so you can see this is how it looks actually right so now i go to login button so double click go there here so on double click i'll take to the code window button one click so when you click the button what you want to do so what we want to do is you want to check what is that in the text box one what is that in the text box too so that we can compare with the by static values we can write the static value here and if there matches then we allowed to go to the next page so how do we do this so if our text box one dot text dot equals if is equal to um let's say abcd so it should be abcd and so it is and text box 2 dot text equals to again abcd okay so let's say abcd so let me close okay so the first open bracket here then we close that bracket over here and here is the one more bracket so that is closed over there and here is one more bracket that is closed here okay so now um so these two conditions one f is equal to abcd and text two is equal to abcd so what we want to do is we give the message box message box dot show and then let's say login successful login successful else in case if is not there so we write else then open parenthesis so again the message box so let me copy the message box and then write over there message box dot so a user id or login id or password not correct our password is not correct right so this is true if both are correct it should so login successful if not it should show login id and password is not correct so let me save this and then let me run this project so abcd then here also i'll write abcd click so login successful so therefore the code is okay if you enter something else here so login id password is not correct so if we give correctly it will take to the next page or it shows the correct message if it's something wrong it will show that password not correct and now here you can see that password you are entering so you don't want to show the password on screen there star has to come or some characters has to come so this is easy select the text box then go to properties there is one property called as a password character so there is a password character here you make it as a star so once you make star and now if you run the project you can see that whatever your type will come as a star now right now what we'll do is if we successful i want to send to another page or another form for that we record one more form so to add the form go to project add form right so this is a form2.cs so this is a windows form so we want to select the windows form here and the name is form2.cs i have not changed the form name let it be by default so this is the form 2 let me make it is maximized and let's change the background color so back color we'll put some other color now so let's say this color now if it's successful so here we tried the code okay and so therefore if successful it should show me the form 2. so therefore it's a form f2 that is equal to new form 2. let's say tf2 dot show you want to show that form and now this message box is not needed so therefore i'll remark the message box so two slashes two forward slashes will remark the code right let us run the project now this is abcd now abcd click login now you can see that next form appeared so this still is there okay so we can hide that form or once you say cancel so here is a cancel so when you cancel the program should end okay so in order to end the application right you need to write application dot exit application dot exit will exit the complete project so i will stop the project so this how we can write the code for static values so these are the static values so it's always abcd only whenever you need to login you have to enter abcd abcd but you don't it not good for always so therefore it always better to connect to the database and then we need to work with the database now let us understand how to create the database so in order to create a database you have to go to server explorer so go to view menu and check server explorer here is a server explorer so click on server explorer so you will have a server explorer here and i suggest you write down all these steps and try yourself to create the same project and if you are successful that is great okay so therefore that's how we can learn but you will get some errors but you need to digest like why the error what is the error and in case if you have difficulties you can write it in a comment box we can help you out on this right so now we have a data connections here so here ah this is the sql server interface why we can able to create the database we can also have a separate interface there also we can create and do the same job therefore i'll just create here only i go to data connections right click i go to add connection add connection here you can see the data source what type of data source you are using i'm using microsoft sql server database file because this is a database file it's easily deployable that means you can copy from one system to other system if you use a server database then you need to take a backup then you need to transfer to other system our access file our worker file okay we can use multiple data types databases but at this moment i am going to use the sql server database file okay click ok then what is the database name so now i'll give the name as a login database i already have one actually so i just for i can say i log into database so login database is already present so therefore i just give us a login to database and where you would like to create so here you can create a new one or you can link to the existing one okay so now i'm presently creating the new one so therefore i go to browse button so now this is a c sharp project and you need to keep this database in bin folder and debug folder so then referencing to this folder will be easy because your exe file will be created in the debug folder so now this is the login2.mdf click open and click ok yes as i told already sometimes we may i get errors now you can see that it is created login to database right so if you expand this you have a tables here and if you expand the tables there are no tables so we need to create table in order to create a table right click here and then go to add new table we can also write queries okay if you know like sql query you can write otherwise here also sql query will be generated i'll show you like how to create a new table here so this is a design actually fine so here you can create but otherwise we can go to sql straight away here is a table name so therefore let's call it as a login table and there is an id integer primary key okay instead of that i'll say login id login id is a column name and this is the integer or i'll take as a worker so let's say work here of 10 and then password so therefore this is the p word so again this work here of 10 maximum 10 characters so we want two columns so therefore login id work return and password done so here we can type here also and we can select the data type here also we'll automatically create the corresponding sql query over there and that you need to execute here is update button click on the update button so update database so okay so now we come back to the server explorer and here you say tables nothing is showing refresh it so therefore you can see there is a login table okay your login table created there are many ways to create the login table even you can use the query so we can go to right click on the new query we can straight away you can write the query here create table table name column name and all we can do it here also fine so next step is you let me put some values here so now to add the values go to show table data show table data and here you can see that there is nothing here i'll write admin then admin user ids admin and password is admin and also i'll write abcd abcd now we can able to login via admin admin or abcdabcd anything else we shouldn't login so close this now our data is saved and our table is ready our database is ready so i think most of things are ready now what i'll do is i'll just modify this okay so this is what are the code is already written i will going to modify this one so in order to connect to the database so we need to know some basics okay the basics is one is we need to use the system.sql client so this is the namespace our library this library we need to use in our to work with the database sql database using system.data.sqlclient in the beginning we need to declare it we need to use this one after that we should know about sql connection sql connection is a connection component so this is one component to connect to the sql database okay so therefore here you can say a new sql connection and you need to give the connection string here therefore you can able to connect to the particular database next one sql command sql command to execute the sql statements here we can execute sql statement like select insert update delete all the commands we can able to execute via sql command my command is a variable name so any name you can give it here so presently we give as a my command okay so this is a new sql command and then uh if we execute sql statement it written the values so sql statement will get back the values that values we need to transfer to the container so therefore sql data reader is a container so what are the data comes will be stored into my reader so it will be there in the my reader of the type sql data reader so therefore three things are important one is sql connection to connect to the back end sql command to execute the sql statements and sql data reader to all the content what are the contents comes from the select statement that will be stored in the sql data reader in this case we declared the myreader so you should know like three things one is sql connection sql command sql data reader so let us come back so let us declare how to do this sorry let us let us try this okay so using uh system dot data dot sql client so we need to add this name space you have to work with the database system.sql client right after that so we need to declare the connection object we need to write the connection object so the connection object will be something like this okay sql connection connection new sql connections fine so here we write sql connection so what is the connection name so let's say c1n is a connection name so new sql connection so then open bracket close bracket so here we need to give the connection string sql connection so then so here sorry i'll just show you so sql connection so you should give any sql connection connection string so we supposed to give the connection string here so now what is the connection string where do you get the connection string that is very very important so now to get the connection string come back to again server explorer select the database log into database.mdf and if you go to properties window here you can see there is a connection string here connection string fine so connection string so how to get the connection string go to server explorer select this and then you come to connection string here so select the complete connection string here copy the connection string in front of connection string you have connection string copy that complete connection string then we can come back here put a double quotes then we need to paste it here now you can see that wherever one backward slash will show some underline so now to avoid this so we need to use at the rate okay so instead of single backward slash you need to make as a double okay so put one more here so there is one more one more fine wherever there is a single backward slash you need to make it as a double fine so now there are no errors so i mean the connection string okay we can remove this and instead of that we can use some global variable that is the data directory that i'll show in the next video fine so our connection is done now connection is done so next step is so we need to create our sql statement so therefore i'll write a string sql str so that is equal to mt okay first let me declare this i can declare outside also so let's go and declare here find sql str so the sql str is equal to you write select star from login table we want to select from the login table where our login id so that is the login id is the column name that is equal to single quote double quote and then we need to join with plus mark and text box one dot text text box one dot text so here the value so what are the value entered that is there in the text box one dot text plus uh we want to join the rest of the statement that is a concatenation so plus is here is acting as a concatenating operator so then single quote then we have to write and and is to check for the next part that is a p word password so that is equal to single quote then double quote then place text box to dot text so what are the value in the text box too plus double quote single quote right so this makes a statement sql statement and executing this statement if returns the value means the data is present in the table if don't return the value it means that data is not present in the database so if not present then you give the message box so data is not present means login id is not valid if it is written the value then you can see that it's okay then we can send to the next page now this has to be executed in the sql command as we discussed already so you require a command object therefore sql command command name cmd1 that is equal to new sql command and here we require two important things one is command string that is a command text what is that sql statement you want to execute and sql connection which is the connection we would like to use right so connection is a connection object so therefore here is sql str this is the statement sql str comma connection so this is the connection object so when you execute this we want to transfer this value to the reader data reader so therefore sql data reader ah let us say dr1 that is equal to so whatever you execute here semd1 dot execute reader so this value should go to the dr1 so when you execute this what are the values you'll return will come back to the dr1 so now dr1 will add the values so first thing we need to check whether dr1 allow the value or not so therefore we write dr1.read dr1 dot read so this is a separate video for this like how to do all these things so please watch that video database connection video so there we will explain all the things in detail right so when you read this it should go to the form 2 otherwise it's you the message box login id or password not correct now in order to work with this so first you need to open the connection so therefore it's a connection dot open so we need to open the connection and then once the work is get over you need to close the connection therefore we go to connection dot close we can close the connection so first we have to open the connection then you have sql command here so sql command then you write the sql query so this is the sql query which is to check whether these values what are the values you enter it is there in the database or not if it is there we're going to read that even it's read true means you'll go to next page if not it'll show the message box okay so this is the number of lines you need to write to check whether the values are present in the table or not fine so important steps are first step is you need to use system.sql client then you need to declare sql connection you need a connection string so you have to go to server explorer and then you have to go to connect string here you need to copy the connection string and wherever one backwards slash you need to make two and then two backward slashes then you need to create sql command sql data reader and all these things fine so now let me run this project okay format of initial string does not specifically starting at the index 60 there is some problem okay okay the error is due to that here is only one backward slash you need to make two so i just made two fine so it's rectified so now i'm going to run it again fine so it's working fine so login id password so let's say admin then admin and i will put some extra character here so click login login id and password not correct because only take for admin and admin so if any extra characters no when it's not matching you shouldn't take actually now it is admin and here is admin click login so it locks in fine now it's successful so what are the values you enter it's check in the this table so if the values are present then only it can able to login now i'll go there and enter abcd then again abcd so click login it should log in fine so otherwise you shouldn't log into the this application so this is how we can write code this is a one method so there are many way you can write the code so this is the simplest way to practice so keep practice this and if you are successful really great and keep watch and keep practice therefore you can learn each day more programming so if you're not yet subscribed to our channel please subscribe to our channel subscription is free so when you subscribe it help us to provide more videos and it will also help you to get our videos easily also please share this video with your friends and family members who are like to learn c shop or any other languages so they'll get the benefit and if you like this video please click the thumbs up so please watch our videos and keep practice in turn you can gain the experience so thank you for watching so in case you would like to contact us here is the contact details please contact using any of these options thank you very much
Info
Channel: Highblix
Views: 18,457
Rating: undefined out of 5
Keywords: C#, VB.net, asp net, php, python, java, jsp, Microsoft sql server, Mysql, Web Application, Project, Final Year, Academic project, idea, new idea, new project, Project source code, Project development, table design, database design, DFD, ER diagram, Case Study, Software development, How to make, SDLC, make project, create project, python project, asp.net, jsp project, Project Idea, Login Page, Admin Page, BE, Me, BCA, MCA, MBA, BTech, MTech, MS, BSC-IT, Diploma
Id: Xebmj7Kjjyw
Channel Id: undefined
Length: 32min 40sec (1960 seconds)
Published: Wed Oct 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.