How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
Key Takeaways
Compares Power BI and MSBI for business intelligence tools
Full Transcript
welcome on behalf of AA I've been in IT industry close to 20 years and I'm an alist of Mumbai University so as you know the topic today is python logging system and I'll cover the different facets or aspects of python login system so here's an agenda quick agenda what is python I'm sure a lot of you out there would know what is python the python features login system and pray requisites objectives so you will see a demo of it as well all right so here's the plan out of this session first I'll go through some theory in this deck after this I'll show a quick demo of how the login screen will look before I actually delve into the code part welcome on behalf of AA I've been in IT industry close to 20 years and I'm an alist of Mumbai University so as topic today is python logging system and I'll cover the different facets or aspects of python loging system so here's an agenda quick agenda what is python I'm sure a lot of you out there would know what is python the python features login system and pray requisites objectives so you will see a demo of it as well all right so here's a plan out of this session first I'll go through some theory in this deck after this I'll show a quick demo of how the login screen will look before before I actually delve into the code part right so what is python it's a scripting programming language and I'm sure everybody would know it's one of the most popular languages programming languages scrip language out there just a small fact it is I know some of these things are not very important from the technical but it's it's a good ice breaker a good think warmup by having this kind of slides I am not sure whether you know the origin of this name python so it was based on some comedy troop called Monty Python it's not the python the snake that you see on most of the cover pages of in fact all the books right so it's not the snake it's actually based on a comedy group so it's a light Fact one of the best things about python is it's the syntax and everything is easy I'm sure most of you would have seen a python code so see any any programming language reading and writing takes different effort right reading is always easier even if you learn a new language whether programming or our own language reading is always easier the writing is always complex the one best thing about python is even if you don't know python much if you read a python you will understand a lot of things it's very int intuitive and that is what it means easy syntax to write yeah you need some practice but to read it's quite simple so features of python so Simplicity like I said it's very simple to understand so there are a lot of libraries lot of features on top of it but the core it's very easy to understand very intuitive and once you have some practice you'll find you prefer it compared a lot of traditional languages programming languages out there and for writing code so source so yeah you can install out there for everyone and you can uh use it for commercially as well and there are package managers Library such as Anaconda I'll come to that portability uh yeah you can run it anywhere you have a python virtual environment or python interpreter you install it somewhere you can put your program even between Windows machine and Linux machine it's very easy to Port without much hassle so one of the most important feature of python is extens ability right so what it means is you can see one of the things with scripting languages since it is I mean especially language like Pyon it's interpreted that is some delay in executing so it's not like you are compiling a code so any compiled code will have a better run for performance for example if you write something in cc++ and compile it it will definitely have a much higher performance as compared to just writing python so one of the best things about python is you can extend it by adding C library so there's something called syon or so what syon is is you can actually Define the variables in Python using some commands like CDF and then what happens is you can then compile it into a c program it becomes a c program but that c program you can directly import into the Python program just like and you would import any other Python program what and these C programs are super fast so basically if you write a just to try your computer write a for for logic iation one million times write a python and you write a syon and then import that syon you'll see drastic Improvement in performance when you run and see so that that extensibility is one of the uh good features of python along with that there's so many libraries out there for python which can be imported so that's I'll cover that in a moment so it's an interpreted language all right so if you write syon you can compile it as a code but essentially it's an interpreter so there's an interpreter which looks at line by line each line of python and then executes and that there's an error it will stop there so it's an interpreted language and that makes it very easy to B python programs advantages Library so this is I mean there are lot of important features of python but I would say this is number one because there a huge open- Source Community working on python who supports different kinds of libraries so anything from socket programming to machine learning deep learning even Quantum Computing so any new technology comes up there will always be python apis or support for Python and while there will be in each space you will have another language competing with py python but you'll see python everywhere and that is parly due to the huge open source Community who like Python and any new guard them out there for example machine learning and deep learning any your La algorithm comes out first you will see a python Library made out of it before you see other technology so that's one great and that's the reason we all want go python or work on python most of the Technologies because that will be a li it's not a silver bullet right you can't use it every place but essentially a lot of new areas like deep learning machine learning cloud computing if you're working with AWS they have a boto library or if it's qu Computing python helps a lot the last part is it's you can write it as a procedural language or you can write it as a objectoriented so supports both flavors all right who uses python yeah so that's a a question that just answered a moment ago across different application they'll find uh you are users of python and justs of different organizations and companies using that so now what is the login system it takes inputs from users right this is a login screen you enter an email ID user ID password you login and then uh if you don't have an account you sign up this is all a login system is and there are few fa aspects of it which I'll explain as we go to the demo part so pray request is for login system right so what are the different blocks that comprise a login system so you have a login form that you just saw a moment ago then registration form for signing up and uh why I'm rushing through some of the slides is because you all could be familiar with what a login from what the sign up because so everything every application nowadays requires some kind of sign up and login so the third part is where the database integration for login authentication yes uh that's where all this information all the user records are stored and the HTTP methods to access come to that log System project objective we will be using flask framework right so those of you are not aware it's a micro framework build python web applications and it also comes with a lightweight web app server web server and that you can FL get is embedded with aate web server and you can actually host web application on using flask framework so one thing what flask is see it's very lightweight it's very easy to understand but and it's also very extensible which means the footprint of a flask framework very light what I mean is very small amount of code be there in a flask framework but you can add lot of other libraries like security or database on top of it and make it complete framework with all the features of a framework and the compartive to flask in the space is Django so Jango and flask these are the top two uh web Frameworks web server and which host lightweight web servers for hosting web applications in Python then database integration there are multiple libraries multiple connectors you can use flas myp you can use anything and the URL the the web page right when you say URL the web page that you saw on the browser communicates with the web server the flask based web server return return in Python using post and get methods uh just hold on to this and when you see the demo and when you see the code this point will get much more clear right so login authentication what all entails in a login authentication so you read the input from the login form again database connection so database connection is basically to authenticate the users authenticate rise uh send those values to database and you will see all this in the demo as well as in the code so this is sign up has been sign up reading again the same flow uh that isn't much different and you all know what a sign up is but uh you know this is the same same standard steps except that you will be inserting into the database when you log in you are reading from the database when you are signing up you are actually uh writing into the database right so now let me show you a simple demo screen right so here's the thing okay so far I showed you a theorical presentation a deck now we as human beings we understand better by visualization than just text right so let me just give a glimpse of what we will be building and then before we jump into the code so here is the login sign up uh screen right and uh I'll just uh put CR7 let me enter credentials so it's saying welcome Cristiano Ronaldo because that's already there in the database right let me R out let me say some other user right put an invalid password there incorrect password for Messi so here's the thing see usually in an Enterprise applications and all the whole login screen using different technology like mostly JavaScript based angular or react GS those kind of Technologies but this is how we build a login screen from python so this session is about that and one thing I want to just mention is usually you will not see this kind of error message invalid password for a user ID because the thing is due to security whether the user ID is incorrect or the password is incorrect you would get a generic message saying hey user ID or password is inval so that you don't tell the person who's logging in hey there's already a user ID for this because this is useful for people who want to do some Mischief if they know there's a user ID existing they can do it also just for demonstration I'm showing the incorrect password but usually you will get a message that whether it's user ID part say invalid all right examp example if I put something it'll say inval user now let me put the correct password for Messi and it will say welcome Messi so this is the profile page all right so understand this what you see here I just remember it notebook you note down this is the profile screen right when I'm saying hey welcome and then I'm showing a logout screen I click on log out it comes back to login screen right this is another HTML login let's say I try to add 20 so so these are different forb players if you don't know them so invalid User it's saying right so let me register I'll say let me enter this email ID and then I'll set up some password that's it so sign up successful you can go back to login screen now let me login this right so it's saying welcome to any CL right so you have a profile page you have a login page and you have a new page sign up all right so this is what you'll be going to see in the in the in the code so now what what do you see here on the left let me show you here so you can ignore SP so there's a login HTML right which is essentially on the HTML page so let me just open it and see how it looks I know all of you have seen HTML but uh just make me run with chrome so this is the pure HTML on Chrome now you'll see what is this Gibb don't worry I'll come to that but rest of the uh objects on the screen you know same thing that you have seen here okay so that's all HTML is and there are three main htmls here login like I said this one login screen then the profile where it says Hey welcome you know Lon Messi and the sign up right new registration that I register 20 okay so I don't want you to I'll walk you through some of this quote but I don't you know want to build it as we walk along because this is something uh you'll get uh so this application I have bu for this particular session and uh you can making this HTML is not a big deal but I'll focus on the python part of it all right so so I want just want to show the flask okay I'm using the flask micr framework here so this is a rough copy what I me to say let me just show you flask before we jump in login part of the screen okay so this is all again uh boiler plate code what I mean is you have a flask Library you import the the class from it and then you define the app so in this case name is actually will be main so you know any new program when you execute it will be main right so I'm this is a standard code so here is where you will find you know how easy it is to run flask okay so what you see here is something called decorators in Python okay so decorators are kind of a wrappers around functions so you have defined a function here and just feed it to The Decorator right and The Decorator will actually make it an endpoint or a the URL so this is a URL that you see and you want to map this URL to a specific function on the web server so this kind mapping is done by The Decorator takes care of linking that URL with the function so what I mean is if I put a slash it'll say hey return hello right so I'm just showing this code to know before you see uh this code and it becomes very complicated let me show you the the smaller code right so I'm just saying uh hello all right so here's the thing uh let me just run this and probably you'll be able to see it right so that's it I just run this program and you see so Local Host so this is binding to some IP address 00 but I'll see something on local Port 5001 okay so let me see 51 what do I have hello all right on this on the screen so what has happened is I have said the URL is you know slash that's it it goes to this function right the browser s um action to this particular uh function and it returns return hello all that's it and that's what you are seeing here let's yeah that's all so now let's say I want to build something so let's say I will just uh right so I don't have a welcome page so not font this URL is not that right so I will just unmend it so I have started I CH change the code automatically the server has started so you can see below right so if you see let me use so you see every time I make some change to the code this restarts here and then if I go and then I restart welcome right so it's as simple as that so that's the beauty of flos in 10 lines you already fired up a web server okay and the last part so you can have you know other something else in of wel command that you can put whatever you want and that's it it's all done and this is just saying from the application a certain you don't worry about all these are Boiler code but just say boiler plate code but what saying is bind to this particular IP address which means means uh you can connect it from local host or any other there's a public IP to This Server then you can connect to that so that's the part of about it right so that's about flask now let me show you the different artifacts right so let me quickly run through the HTML because this is more of a python web server or a login system so let me I'll focus on the python side let me just quickly show you some of the control so I have a user field HTML so you don't have no HTML I'm just highlighting uh certain parts of it which so if you see there is a user right which you saw on the screen this user is there then there is a password right which is again you see password and that's it and then I enter this so what happens is so let me switch back to my so when I hit enter on this particular web page right login or something what happens there is an action right this is inside a form object HML it's an action which says slash login right so when you hit enter on HML screen it's the action is to call uh endpoint SL login and that slash login I have defined in my main program right SL login and it's a big code so I don't want to uh confuse you at this point of time okay so let me uh go step by step but that's what happens it comes to the login screen right now one thing uh I'll cover each aspects of flask right and how each each of this function helps you in defining or firing up the web server or serving the URL and end of the day we enter user we enter password we click login it'll come to this particular method and then what happens is what we will see right now before that let me show you this right so so what I showed you earlier was a rough one a simple 169 code so that you can understand how simple flask is now I come to the main code initial Parts initial it's all same right instead of app I'm saying Main and uh blueprint is nothing just like an application so each application can be one so if you have multiple application that could be multiple blueprints so you not to worry about all that it's just that simplistically main is a map that's why I say main. route if I put slash on the browser it should take me to the index and what is the index doing there's something called redirect right uh redirect means you have to if there is nothing happening on the screen it should redirect to the main. login right so redirect URL for main. login main is this name of the program okay so redirect main. login main is the name of the application and login is the name of the function here right so what happens if I go back to the browser and I will not put any logins anything I'll just put slash that's it it still gets automatically redirected uh to the login right in case let's say I have uh put something else right return let's say I heard return render template I'll tell you what render template is for a sign up. HTML right and I'll comment this out so now what I'm saying if I hit slash right it should go and render so render is a technical D it's just like rendering a template or rendering a HTML on the browser so if it's a slash don't redirect to login just show me sign up. HTML right so let me try that again see now it's not taking me to login now it is to bring me to a signup screen okay so just it's like one line you can move here and there so that's some of the things flask makes your life very easy on the respect let me restore the world to its normal order right so yeah it goes to login right that's it so now let's move on to the other the next part of it all right so for now uh let me just create a copy of it or let me create in the folder itself I have a copy this main uh let me just remove it everything just what is there come to that later okay so now what login happen when when I do login this is what is happening I'm setting under template login. HTML and that's why when I say login or whether it is whatever it is coming to this particular page right similarly new right new is the name that I have give for a sign up all right so if that is sign up request let's say I say new all right so what will happen if it's new I'll render this HTML page on the browser I'm I'm basically returning this particular template or HTML to the main screen right so I'll say new comes a register screen right similarly there a third screen that I said right profile now you are saying render template profile HTML so let me say profile and some user all right let me just say profile say not F right so now let's say I say right so see name full name and all is not that because it's expecting uh full name right I'll say full name equal to know and now let me run it so uh takes a while for sometimes I'm saying welcome L messy right so basically if I don't have any code I just say render render render I'll see those pages okay but uh that is so log out I'll cover later okay because once we complete everything else we'll move on to the log out part right so now let's go one by one right so when we are logging in okay here I have put something called error right so for now you can ignore it I'll show it towards the end there's something called template Ginger templates on HTML screens for dynamic rendering of pages so I know what I just said but sounds very abstract hence don't worry about error for now you just see Rend render template understand that that a render template is to render a specific HTML onto the browser and redirect is to direct it to some function right so I'm redirecting to this function and this will do the Rend ring okay uh that's about it now there's one other thing I I want to touch upon right called session okay so what happens is when you login to a screen so your user your some of your details are actually stored in session variables or cookies so that's why you know any application you go you go to multiple Pages it recognize it is you it doesn't ask you to enter your password at every every every step right so it holds some session information so that's something once you log in it is able to the application will tell you hey you are the so and so person so it will show all the different pages in the web application that is why earlier when I typed in Tony Tony Cruz and loged saying welcome Tony Cruz because the session variable is a session is a variable which still stores Tony Cruz and and then until I say log out it will not clear the session variable okay and now nothing will happen because it's all I'm still running with the older code so I just remove a lot of code but I'm just saying that takes you out okay the whole session for the whole session information is removed all right so let me now talk about one other aspect in this main do route so like I said this is um this is a decorator decorator function right this this works on this function so it's a wrapper around the function so one is the URL other is the methods okay so I'm not sure you know how many of you understand the post and the get HP methods but let me talk about that a little bit so when we send a request from the front end to the server so either we do a get that means we I want to see some request from database so I I send a get request I get me some details on the screen the other is the post where I'm submitting a form I'm submitting some details so it's a post and then it gets updated into the database variable so that is the post part of it and that's another aspect that gives depending on it's a post or uh get we can do uh different things okay now let me not write some code around it so let's say it's a login okay now when we login what what should happen so if you go to the login HTML right it says login and Method post so I'm submitting the username and the password all right so I will go to Main and I'll just say uh if request request is one of the um the methods or class classes within the flask library right so when you submit certain information from the HTML page you can find it under request all right so this is a object which holds uh all this the different information that is sent from the browser so if you say thir is equal to post because I'm saying it's a post request right so I'm saying if request is equal to post let me take down those requests right let's say user is equal to user is a local variable so I'll say request dot request. form that start the so from so I'm submitting a form here let me go to the login HTML so I'm submitting a form right hence uh you'll say request. form and then you will have user okay and then uh I will take the password right same same syntax request.com so what is let me look at the password name so if you see uh let me yeah user is uh name is user and uh password is uh yeah PSW right just abouto PW so let me erase yeah so PSW so this is the password field all right and then uh see here's the thing now fine the user has entered user and password but how do we know whether the user is existing or not for that you need database right otherwise how will the program know and that is where I'm just introduce you to this particular mySQL rdbms database that's what I'm using here okay you can use any kind of database for holding this information but my Rec common uh it's also an open source and uh it's pretty powerful so I'm using mySQL database on AWS Cloud so this is not hosted locally I will hosted on the AWS cloud and I'll show you how the table looks because now that you have entered the user and the password someone has to go and verify in the database right so how do you do that so that's where we have this let me open that specific show open editors so model.py all right so one thing is uh just in the interest of the time and the depth of the subject I'll focus on the CL flask web server but I'll just quickly run you through what this my model program does is it has a MySQL API right and there are some I'm giving four details right if I want to connect to a database I need four details one is the IP address so this is the IP address or in this case it's called DNS yeah domain name system DNS of the uh mySQL database on a WS Cloud database is Dev user ID is admin and password if you see it's a big brish I'll tell you why it's longish in a moment but let me show you the table right so this is a MySQL workbench this is also an open source tool you can use to connect to mySQL database on your local or anywhere in the world as long as it's you can connected as a public DNS all right so this is the name of my table user and if you see I have four records already created right CR7 Kane Kan man and Messi and the so this is how I check whether the user is existing in this table or not so I'll just check usern name is the primary key I believe you know I mean I'm sure all of you know what is a primary key so there's a primary key and based on that I check the record is existing if it's not existing I have to insert a row right that is how sign up happens and if you see the password it's all gibbish reason being I'm actually hashing it never a good idea to save passwords the true password in programs or in database hence I'm using something called hashing what is hashing yeah that's again a separate uh topic but uh just know for now that uh whenever you send information in a secure website right your your your passwords either get encrypted or it get hashed right there are two ways uh so encryption means you encrypt something you can decrypt using same key somewhere else right in case of hashing it's there is no unhinged hash you cannot extract the password out from a hash it's just like every time you know enter a new you enter a password the program will apply hashing algorithm on that and then it will go and check the hash value and then it will say it's matching or not but nobody can know looking the database or the program saying hey what's the password entered no way because it's all hashed all right the other form is encryption but with encryption you can also decrypt using a key okay so basically that is that that is what hashing the difference between hashing and encryption is right so I'll just walk you through some of this I'm connecting there a host host user password so what I'm doing here is uh instead of uh hash I'm using a encryption decryption here so I have this is an encrypted value of the password Crypt do decrypt will decode it right decrypt is a decoding function and I will not touch upon those uh topics here just so that not to confuse but cryp is another program that I had written to encrypt and decrypt so there are encrypt function decrypt function hash function etc etc but not to worry just know that there is a function which rec the password and then in this model model.py is the one that interacts with mySQL that is why it has a MySQL connector imported right and it has a cryptographic module also imported so this connection is established and there are a few methods this is get row get row is saying hey select Sol from user where username is equal to this so this is what the login screen does right it has to go and query the table and say hey select me a details from username and it'll execute so this is all syntactical okay you don't have to worry much see one thing about is syntax a lot of these open source Technologies you will find the syntax everything on web online it's all out there so you don't have to worry too much about the syntax you will find that just about understanding what all libraries are there what all functions are there what all features are there so that you can execute it you don't have to by hard anything so this is the query cursor execute is saying just execute right and cursor is again you know I have a connection variable here so I'm connecting to my SQL cursor is uh another handle from the from the connection and I'm executing that handle here executing the query and I get the row and I'm getting the row so this is just getting the row for me next one is something called user exist now I'm asking this program this function hey does the user exist or not and then the same thing it does it says model. getet row it calls this function and then it's saying if the row count is one cool at least the row is existing so it is taking the DB password right what is the DB password so I entered Messi right and it's it show it told me hey welcome Messi because it was able to identify message from the database so here it's saying hey database password is equal to something that something is coming from my SQL table this is that something right for the Messi this is the password and that gets R TR here and then what this program is checking is whatever is fetched from the database all the gibberish and whatever I have entered on the screen I'm hashing that I'm hashing that password generating a gibbish hashed it's not a gibbish actually I'm just saying for simplity but a hashed password and I'm comparing it to Hash password and if it's perfectly matching I'm saying returning zero zero means all is perfect all is well I'm returning one when the user is existing but the password is invalid right user is that but password I have put invalid and I'm returning to when the user itself does not exist all right so that is what the model is doing here and the user exist so just remember user exist is a function which says gets data from other database validates the password and returns get full name well as the name sest is getting a full name so full name is a you see here you can see highlighted full name right so full name is that it just fetches the full name that's it there's not much into it and then the last part is me erase this marker the last is add user so where would add user be useful of course for sign up so I'm taking email ID username password full name everything I'm applying again hashing algorithm on the password that's all I have to do after that I'm inserting it query this is standard SQL okay again like I said don't pret about the syntax and all it's all can find online it's not you don't to mug up that mug up syntax it's inserting into the table user with all the values and then it's executing the query and that's committing that's it so SQL commit that's it and then uh you have everything you need in the model.py and that is the reason I have in the main I have imported from model I importing main function model and from cryp typographic I'm importing the main function CP and I'm using those two so what I showed you just a moment this model model program all right just remember this is the handle we are using for a logging in okay so I have taken the password right now let's say I save this okay I save this and now I will go to login let's say what happens sorry no loog and login it's login right let's say I say CR7 then I say CR7 nothing happens right so I have a record and nothing happens that's because I removed the code right I deleted I'm not doing anything it's just saying render template it's not taking me to the profile page earlier what was happening was taking to my profile P saying hey welcome Christian Ronaldo but not now because I have removed the code so let me add that code but first I have to know whether this user ID and password is valid right so I will say let's define some variable this standard variable can you submitting and then model is the program that I mentioned which contains the database calls and user yeah user exists I'm going to Ty but because I imported I can see a drop down I click on it user exists and I pass the two parameter user and password so so you can break your programs functions small small pieces right always so you don't have to worry about writing in one big code everything so this it makes your life easy troubleshooting so user valid is a variable which contains three values 0o one and two right so I said zero means all is all is well one is invalid password two is well the user does not exist so I'm checking that if user so one thing so all the ID S one good thing about all these IDs is the variables pop up even if that part of it and you all know that already but I'm just mentioning it here okay uh so I will just say return and I want to redirect it to the so this is see here's the thing all right I can directly render the page which is the profile page right I can directly render the profile page or I already have a profile function here which renders the profile page so let me just redirect to this particular function so that makes my life easy right so whatever I do in that particular function this function will not get impacted I can change that function only here I'm just redirecting and I'm saying main is the name of main. profile so that's all what I'm going to do and uh that's one more thing so profile I also need a username right because like I said earlier if it's Messi it should say Le Messi or the user name we have to pass right that's how it is able to render and let's pass that username in this redirect right so main do profile and I will say user is equal to user so this is what that's it all right so that's all you have to do for if the user is perfect or the user is existing database the next thing is if I user is not let's say the password is invalid okay in that case I just uh user is invalid let's say invalid so the third scenario is the user does not even exist right and this here uh we'll say here is invalid because user does not exist here password is incorrect for user okay so we we just want to add that so let me reiterate it's a post function and then I have request. form a password user valid I'm checking if yeah user is existing I'm passing to the profile page here saying password is incorrect and last part is user is invalid when it isn't existing in the database right so that's all it is and then I'm entering the uh login page so if let's say the request is not post some other request it it will continue to stay on the login page however the request is a post and user is valid it will redirect to the profile page okay let's run this let me restart it's saying I go to the profile let me go to login so I will go to the initial login screen right so I'll say Messi and I will enter messy let's may put a valid password login see now it has so earlier it was not going in now it's going to the profile page right because I am redirecting to the profile page if the user is valid so one thing is I entered just messy but how does it know Leon Messi that's because it's fetching the full name I actually I hardcoded here but uh in this case let me remove it right so I just hardcore because uh to De demonstrate but we can actually enhance this prefix page so we have to update so let me not put that let me just go back log out okay and let me enter Messi again and we'll see what happens I'll say Messi and I'll say yeah so full name is not defined right there's no full name that means the profile function is not complete I need to get the full name then only I can display it right so let me do this I will full name is equal to so we saw right there was a function in model extract full name get full name right okay get full name fine model do get full name it gives me this and then what do I have to pass I have to pass obviously the user since that is a key okay now I'm rering the template profile. HTML F name is equal to full name I'm passing full name but what is f name well let's go to file HTML I will look at the let me Scroll once so that you can see F name somewhere here profile yeah so as you see uh let me highlight it f name so it's saying welcome F name right and that is what full name giv past year okay so now you'll wonder what all this open braces and all are I'll come to that in a moment right so now I go to main I have set the full name full name is equal to model get full name I'm passing the parameter now let me restart the server or server gets Auto restart every time I change the program okay so here what I'm doing is I'm just ping some data with valid password and saying welcome all youy and just so that you don't think there is some kind of trick here put harricane right password is incorrect for Kan now right Kan is existing but I put an invalid password for it saying welcome harri kanane why because Harry kanane is there in the database harri Kane full name right as you see here second row so we have basically constructed uh the from login to the profile page okay now let's quickly go to the sign up or sign up page right so what happens when I say new it takes me to the sign up page right now let me build so this is where it comes right now nothing is happening right if I say sign register let me fill something something nothing is happening because I don't have any program here right I haven't put any code now I have to do I have to add a user the moment that is a sign up request right I have to add a user so that's what the new function will do okay so the first thing that we need to do is yeah we are checking if the uh see again when you go to the sign up page when you go from login screen to the sign up page you are just showing an empty screen but once you enter the details and submit and then you click on register it's a post HTTP method right post so you're entering submitting data to the Spen server right so let's put it as poost right so if um so what is that request. method the same code that we had earlier right so we are just we're looking at the request variable we're posting it and now here's the thing we have to get the details so all the four details that we are going to fill because if right now if I say hry hry is hry existing hry is not existing I'll say entry okay Sol there in your cash so I'll say the hre and nothing happened why because I Haven I haven't written full code so here's the thing I'll say now let me put that code request. form right user password is equal to request. form uh PSW sorry password and uh email is equal to request. form email and the last part is what full name full so this can be any name okay is local variables but one in the square bracket should be coming from HTML yeah so that's what I did now what I'm going to do next is I have to insert this right so I'll say model do add user that was the function right so in that add user we have to pass multiple variables let's let me use the AR uh star AR can email so what order I'm expecting the model add user okay email ID user password and full name all right email ID user password and full name so I'm passing the and let me get some it returns from status right so anything anytime we add anything we need to check for the status here there are two statuses if the insert is successful I'll get zero if there is an error I'll get two and if the user is already existing then I'll get a return one right so zero means everything is cool right let me just say status status is equal to model the status the SQL code basically yeah that's the term uh let's call it SQL code better otherwise it can mean something else right SQL code is equal to zero so everything is perfect okay when everything is perfect now you'll think what am I adding now flash okay flash is another way another Library within flask to show messages on the HTML okay it's as simple as that you just have flash you put some messages inside it and you are good to go and you can say use yeah sign up you can just sign up successful yeah go back to login screen because we have to direct that that is one thing then I have FF SQL code is equal to one when SQL code is equal to one and we are saying what is one one one means the user is existing is user is existing okay and U only thing is we just say user is existing username we have the username L if and uh this is another good thing about all these IDs it will tell you if there's an error right right away and then flash if the user is not existing yeah some or insert failed it could be anything server not available right server issue you can put something of that sort and that's it so now let me run this program sign up okay refresh so this time when I enter some okay so render template sign up. HTML there is some syntax error return template sign up. HTML right so I have add something here uh what is it saying so there is an issue just troubleshoot it quickly sign up successful skill code is model. add user user is equal to user password sign up. HTML okay uh this is sign up. HTML okay and let me just it should not matter but maybe didn't get refreshed okay so indentation problem it's saying SQL code else LF SQL code right so let me see okay sorry I did some indentation problem so that's something you to be careful with python right I just put some space additional by mistake and through eror okay but again that's fine all the IDS will show all those errors so that's really nice of it so let me now try to register Jer Andre and uh let me put the password right so user is already existing why because I have already registered Theon in the past right saying so let me try I'm just executing the query here in the database so this is a MySQL workbench so this is a good way that to know what all values are exist so Henry is already there okay so we are short of players okay roon is not there let me put roon roone uh say okay that the cash pone and that's it password yeah sign upful go back to thing go back to L and then roone and that's it so uh welcome V Rooney so basically what we have seen is uh most important login screen and what it does you saw it takes input and checks validates and returns message accordingly then you have um the new which is sign up just now we saw so you saw this sign up successful message at the top which gets flashed and then the profile page where it says welcome so these three we have seen we haven't seen log out but uh I think so here's the thing okay I have introduced uh during while I was walking walking you through the code didn't introduce a session variable uh just so that I didn't want to make things complex session variable is where we have to hold some values of the user at the client side or maybe a server side but usually there are multiple ways but we store it at a client client side session information and then if you want to log out we have to remove it from the session variable so just let me not make it more complex because it's not entirely relevant this part but just know for that and uh one last part that I want to show you is we are actually making this uh there's an init program right this initialization program which actually calls the main program so I showed you main program but uh init program is the driver this is where the entry point is so you'll see from flask same command except that there's one app. secret key that you give when you start an application so what happens is when you send session information to the client side you need to encrypt it and coded so FL takes care of that that's why you give a secret key at the start the session for is all encrypted and then you are importing the main function that I showed you all along then you're registering the blueprint blueprint is like I said an app within main that's it so this is again a boiler plate code uh it's you don't have to worry about the standard code here is where main is where I walked you through the various the you know the manuvering across various screens you can control through through main.py okay and uh just to reiterate quickly uh what work we have done so far or what are the important components of this login screen like I said lit is initialization where the control comes here and this function create uncore app is executed when you start the server and within that create you're setting a secret key you are importing the main and you are registering the app called Main and once that happens main starts executing and Main has different routes different URLs end points which will serve the different actions on the uh the UI side right the browser side and there are couple of other modules model.py it adds user it gets full name it checks users all that stuff and there is one CP prog graphy module uh which is this again add just for this for encrypting decrypting the password that is entered right so there are two passwords here right one is the database password other is the password that I enter as a user so as a user I can enter any password hence I'll hash it and store it in the database as highest value the database password I'm only I know obviously only I should know and since I should not uh expose it and in in open in the public so that's why I have the encrypted password and then I'm decrypting it while I'm connecting so and for decrypting encrypting there is something called um some keys so I'm using specific key so which I mean you can see your key and you can encrypt doesn't matter but I'm just saying real time application you will have this kind of encryption and encrytion right then hasing so these are the different uh modules you don't have to worry too much about model and cryptography this is where the heart of the program is and this is what I would recommend suggest to go back and have a look because this is the main part of it all right thank you very much have a good day ahead bye
Original Description
🔥𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐏𝐲𝐭𝐡𝐨𝐧 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐂𝐨𝐮𝐫𝐬𝐞 : https://www.edureka.co/python-programming-certification-training (Use code "𝐘𝐎𝐔𝐓𝐔𝐁𝐄𝟐𝟎")
This Edureka video on the "How to Create Login System using Python" will help you in building a login system in a step by step manner.
Topics covered in this video:
00:00:00 Introduction
00:00:17 Agenda
00:00:43 What is Python
00:01: 51 Features of Python
00:05:24 Who uses Python
00:05:41 What is a Login System
00:06:03 Prerequisites for Login System
00:06:33 Python Login System Project Objective
00:07:58 Login Authentication
00:08:22 New Users Registration
00:08:39 Hands-On
🔴 Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV
📝Feel free to share your comments below.📝
🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐎𝐧𝐥𝐢𝐧𝐞 𝐓𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐚𝐧𝐝 𝐂𝐞𝐫𝐭𝐢𝐟𝐢𝐜𝐚𝐭𝐢𝐨𝐧𝐬
🔵 DevOps Online Training: http://bit.ly/3VkBRUT
🌕 AWS Online Training: http://bit.ly/3ADYwDY
🔵 React Online Training: http://bit.ly/3Vc4yDw
🌕 Tableau Online Training: http://bit.ly/3guTe6J
🔵 Power BI Online Training: http://bit.ly/3VntjMY
🌕 Selenium Online Training: http://bit.ly/3EVDtis
🔵 PMP Online Training: http://bit.ly/3XugO44
🌕 Salesforce Online Training: http://bit.ly/3OsAXDH
🔵 Cybersecurity Online Training: http://bit.ly/3tXgw8t
🌕 Java Online Training: http://bit.ly/3tRxghg
🔵 Big Data Online Training: http://bit.ly/3EvUqP5
🌕 RPA Online Training: http://bit.ly/3GFHKYB
🔵 Python Online Training: http://bit.ly/3Oubt8M
🌕 Azure Online Training: http://bit.ly/3i4P85F
🔵 GCP Online Training: http://bit.ly/3VkCzS3
🌕 Microservices Online Training: http://bit.ly/3gxYqqv
🔵 Data Science Online Training: http://bit.ly/3V3nLrc
🌕 CEHv12 Online Training: http://bit.ly/3Vhq8Hj
🔵 Angular Online Training: http://bit.ly/3EYcCTe
🔴 𝐄𝐝𝐮𝐫𝐞𝐤𝐚 𝐑𝐨𝐥𝐞-𝐁𝐚𝐬𝐞𝐝 𝐂𝐨𝐮𝐫𝐬𝐞𝐬
🔵 DevOps Engineer Masters Program: http://bit.ly/3Oud9PC
🌕 Cloud Architect Masters Progra
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from edureka! · edureka! · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
ChatGPT Not Working - 4 Fixes | How To Fix ChatGPT Not Working | Why Is ChatGPT Not Working |Edureka
edureka!
Advanced Java script Tutorial | JavaScript Training | JavaScript Programming | Edureka Rewind
edureka!
Java script interview question and answers | Java script training | Edureka Rewind
edureka!
OpenAI API Tutorial using Python | How to use OpenAI GPT-3 API - Ada Babbage Curie Davinci | Edureka
edureka!
What is Unsupervised Learning ? | Unsupervised Learning Algorithms| Machine Learning | Edureka
edureka!
Top 10 Applications of Machine Learning in 2023 | Machine Learning Training | Edureka Rewind - 7
edureka!
Machine Learning Engineer Career Path in 2023 | Machine Learning Tutorial | Edureka Rewind - 6
edureka!
10 Must Have Machine Learning Engineer Skills That Will Get You Hired | Edureka Rewind - 7
edureka!
Data Structures in Python | Data Structures and Algorithms in Python | Edureka | Python Live - 5
edureka!
Python Lists | List in Python | Python Training | Edureka Rewind
edureka!
Predictive Analysis Using Python | Learn to Build Predictive Models | Python Training | Edureka
edureka!
Machine Learning Tutorial | Machine Learning Algorithm | Machine Learning Engineer Program | Edureka
edureka!
How to use Pandas in Python | Python Pandas Tutorial | Python Tutorial | Edureka Rewind
edureka!
Parameters in Tableau | Tableau Parameters Examples | Tableau Tutorial | Edureka Rewind
edureka!
Top 10 Reasons to Learn Tableau in 2023 | Tableau Certification | Tableau | Edureka Rewind
edureka!
Tableau Developer Roles & Responsibilities | Become A Tableau Developer | Tableau | Edureka Rewind
edureka!
Deep Learning With Python | Deep Learning Tutorial For Beginners | Edureka Rewind
edureka!
Realtime Object Detection | Object Detection with TensorFlow | Edureka | Deep Learning Rewind - 2
edureka!
Top 20 Tableau Tips and Tricks in 20 Minutes | Tableau Tutorial | Tableau Training | Edureka Rewind
edureka!
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
ReactJS Installation Tutorial | ReactJS Installation On Windows | ReactJS Tutorial | Edureka Rewind
edureka!
Phases in Cybersecurity | Cybersecurity Training | Edureka | Cybersecurity Rewind - 2
edureka!
What Is React | ReactJS Tutorial for Beginners | ReactJS Training | Edureka Rewind
edureka!
Cybersecurity Frameworks Tutorial | Cybersecurity Training | Edureka | Cybersecurity Rewind- 2
edureka!
React vs Angular 4 | Angular 2 vs React | React & Angular | ReactJS Training | Edureka Rewind - 5
edureka!
ReactJS Components Life-Cycle Tutorial | React Tutorial for Beginners | Edureka Rewind
edureka!
Ethical Hacking using Kali Linux | Ethical Hacking Tutorial | Edureka | Cybersecurity Rewind - 3
edureka!
Types Of Artificial Intelligence | Artificial Intelligence Explained | What is AI? | Edureka
edureka!
Top 10 Applications Of Artificial Intelligence in 2023 | Artificial Intelligence| Edureka Rewind
edureka!
The Future of AI | How will Artificial Intelligence Change the World in 2023? | Edureka Rewind
edureka!
What is Artificial Intelligence | Artificial Intelligence Tutorial For Beginners | Edureka Rewind
edureka!
Google Cloud IAM | Identity & Access Management on GCP | Edureka | GCP Rewind - 5
edureka!
Google Cloud AI Platform Tutorial | Google Cloud AI Platform | GCP Training | Edureka Rewind
edureka!
Projects in Google Cloud Platform | GCP Project Structure | GCP Training | Edureka Rewind
edureka!
How to Become a Data Scientist | Data Scientist Skills | Data Science Training | Edureka Rewind - 3
edureka!
Agglomerative and Divisive Hierarchical Clustering Explained | Data Science Training | Edureka Live
edureka!
Climate Change Prediction using Time Series | Python Projects | Edureka | DS Rewind - 5
edureka!
Data Science Project - Covid-19 Data Analysis | Python Training | Edureka | DS Rewind - 6
edureka!
What is Honeycode? | Introduction to Honeycode | Edureka
edureka!
Difference between Amazon AWS and Google Cloud | GCP Training Google Cloud | Edureka Live
edureka!
DevOps Lifecycle | Introduction To DevOps | DevOps Tools | What is DevOps? | Edureka Rewind
edureka!
Introduction to DevOps | DevOps Tutorial for Beginners | DevOps Tools | DevOps | Edureka Rewind
edureka!
How to Create Login System using Python | Python Programming Tutorial | Edureka Rewind
edureka!
Python Developer | How to become Python Developer | Python Tutorial | Edureka Rewind
edureka!
How to become a Data Engineer | Complete Roadmap to become a Data Engineer| Data Engineer | Edureka
edureka!
Azure Data Engineer Certification [DP 203] | How to Become Azure Data Engineer [2023] | Edureka
edureka!
Data Analyst vs Data Engineer vs Data Scientist | Data Analytics Masters Program | Edureka Rewind
edureka!
DevOps Engineer day-to-day Activities | DevOps Engineer Responsibilities | Edureka Rewind
edureka!
How to Become a DevOps Engineer? | DevOps Engineer Roadmap | Edureka | DevOps Rewind
edureka!
How to Become a Data Engineer? | Data Engineering Training | Edureka
edureka!
How To Become A Big Data Engineer? | Big Data Engineer Roadmap | Edureka Rewind
edureka!
Python Integration for Power BI and Predictive Analytics | Power BI Training | Edureka
edureka!
Power BI KPI Indicators Tutorial | Custom Visuals In Power BI | Power BI Training | Edureka Rewind
edureka!
Apache HBase Tutorial For Beginners | What is Apache HBase? | Big Data Training | Edureka Rewind
edureka!
Big Data Hadoop Tutorial For Beginners | Hadoop Training | Big Data Tutorial | Edureka Rewind
edureka!
Big Data Analytics | Big Data Analytics Use-Cases | Big Data Tutorial | Edureka Rewind
edureka!
What Is Power BI? | Introduction To Microsoft Power BI | Power BI Training | Edureka Rewind
edureka!
Triggers in Salesforce | Salesforce Apex Triggers | Salesforce Tutorial | Edureka Rewind
edureka!
How To Become A Salesforce Developer | Salesforce For Beginners| Salesforce Training Edureka Rewind
edureka!
Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial | Edureka Rewind
edureka!
Related AI Lessons
⚡
⚡
⚡
⚡
Docker Explained: From “What Even Is This” to Deploying a Full-Stack App
Medium · DevOps
I Used to Pay for Cloud Servers. Then I Found a Way to Run One Free, 24/7
Medium · AI
KEDA 2026: Event-Driven Autoscaling Patterns That Shrank Our AWS Bill by 40%
Medium · DevOps
AWS CloudFormation and CDK Explained: Infrastructure as Code on AWS
Medium · DevOps
Chapters (10)
Introduction
0:17
Agenda
0:43
What is Python
5:24
Who uses Python
5:41
What is a Login System
6:03
Prerequisites for Login System
6:33
Python Login System Project Objective
7:58
Login Authentication
8:22
New Users Registration
8:39
Hands-On
🎓
Tutor Explanation
DeepCamp AI