Python Tutorial: Create a Passwords Vault App #1 | GUI & Login Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to another tutorial so first things off i just want to say thank you very much for all the support even though i'm like a very small youtuber like 22 subs you guys commented that you liked the tutorials and uh yeah so i'm here making more so this tutorial series is going to be making a password vault so basically it's like an app where you can store your passwords and not forget them so you can have like very hard passwords on like gmail and whatever and you don't have to remember like all the symbols and the numbers and the letters so yeah so first thing i'm just gonna show you what we're gonna make this episode so here let me delete this so uh the first time you open the the app it's gonna pop up with this and it's gonna tell you to choose a master password and uh yeah so let's just do test and test save it and then it shows us our password today we won't be doing the password yet we'll do that next episode but yeah and even if i quit the app when i relaunch it instead of bringing me to the page to make a password it tells me to enter the password that i entered last time so now i enter test and there we go it works so basically the first time you open the app you create the password and then all the other times you just enter the password then you get access to the password and all the passwords in the database so we're going to be using databases uh it's called sqlite all the passwords in the databases are hashed so even if someone were to get access to the database right which they can it's pretty easy the password will be encrypted and basically really hard to decrypt so yeah let's get straight into the coding and see you guys [Music] hey guys so uh welcome to the coding part video so let's get started first thing you're going to want to import sql like three and hash lib so that's for the databases sqli3 and hash lib is to hash the passwords uh and then from take enter import and then star so this is to make the windows like the pop-ups the actual app okay well first thing you want to do which we do every time window is equal to tk and then parentheses and uh we can put a title real quick so window.title is gonna be password vault password and then at the end of your code you wanna put window dot main loop okay so we have our main thing and then we can launch this and there we go so we have a password vault blah blah blah okay so uh first thing we want to do let's do a function so def uh login screen so let's do always login screen okay so then in here uh we want to put geometry so window.geometry and then let's do 350 sorry 350 by 150 and okay next thing we want to do is add a label so label is equal to label uh window and text is equal to enter master password okay there we go and uh label dot oh yeah by the way instead of doing label dot grid and placing it with like paddings and everything i found a new thing which we can do label.config and then anchor is equal to center sorry without the quotation marks but yeah so label.config anchor is equal to center and then instead of doing label.grid label.pack all right uh i forgot to um call the function so all the way down here let's call login screen and then press that and there you go so enter master password it's in the middle we don't have to write any paddings or anything okay next thing we want to add is probably a text entry so text is equal to entry window and then we're gonna put uh width is equal to 10 strike 10 and then this time you don't actually have to do label.config you can just do label.pack and it's automatically going to be in the middle so we only have to do it once and actually what we're going to do is make this a little bigger let's try 20. okay yeah 20 looks good uh now one thing we can do we can make this smaller because it's kind of big for what we really need so just make it like 250 by 100 okay yeah we can keep this for now okay enter master password and then this and then last thing we need is a button so button is equal to button and then window and text is equal to sub submit sir submit and then you do button.pack and there we go right and then we have the button and the master password and everything and look right here right it's stuck to the text entry so if you still want to have some padding on the axis you can do pad y equals and then let's do five so you can still use pad y and pad x which is great so there you go now we have a little bit of spacing let me add actually a tiny bit more and yeah we should be good okay there we go okay so now what we want to do so this is like the function part we want to do command is equal to check password okay and then you're gonna copy this and make sure you make this above the button because if it's below it won't work because it will call it like before it's made so basically we make a function with the exact same name exact same capitalization everything so when they click the button it's gonna like check this so we can just make sure it works print test and then we go here go and then submit and there you go it says test also just real quick on the text you can do text dot focus just for it to focus on the text so when we launch it the thing's already on the text okay now let's make the actual check password command so what we're gonna do is if so we're gonna create a password variable for now we're just going to make the password test now we're going to do if pat yeah if password is equal to uh sorry text dot get so if they're equal and make sure you put two equal signs or then it doesn't work if they're equal then we wanna uh right password and if it's wrong so we do else else and for now just right passing this is just like a placeholder and uh what we want to do is below this label you can copy this you can remove this and then what you want to do is put this text to zero so like nothing like empty the text actually you can even remove the text just remove the text and name this label one and then take label one and in the else statement do label one dot config and then text is equal to wrong password uh actually you know what let's put this under the text entry just because it's gonna look better so yeah so basically it's gonna tell you the text is equal so let's just test it so if i put the wrong password so let's just put some gibberish it's gonna say wrong password and if i put the right password in console it's gonna say right password so everything works good for now now also one thing we can do is uh on the text instead of it showing the passwords directly we can do show is equal to and then quotation mark start so then when you type it's headed so yeah that's pretty good for the purposes of the tutorial i'll take it off but you should probably do it so just put comma show is equal to star okay and the next thing we want to do we want to make a new function so let's do def and this is gonna be just uh the vault so password vote so if you put the right password it's gonna bring you to this page so first thing you want to do in the password vault is actually to type 4 widget in window dot w info underscore children and then parentheses and uh two dots widgets sorry with widget dot destroy and parentheses so what this is going to do is when we switch from the login screen to the password vault it's gonna destroy all the text and everything because if we don't do this i'll i'll show you later it's gonna keep all the text like it's gonna stack on top of each other so that's not what we want so and then uh next thing we're gonna do is uh we can make this screen so we can copy the window.geometry make it probably a little bigger so let's do 700 because this is going to contain all the passwords 700 and then we can do like 350 so it's nice and equal and then let's just make a label real quick we don't have to make this complicated yet because for this uh lecture like for this tutorial we won't actually uh be making uh this uh window like we won't be adding the passwords either way text password evolves and then we can just copy this label.config anchor is equal to center and label.pack okay and then in here where we did print right password instead you want to run password vault so now what should happen is let me make sure yeah i got everything right you press on the run and then you enter the password so our password is test so let's put a random password doesn't work and then if we put test there we go access to the password so yeah that's uh that works all good now one thing just before we move on to the actual hard loading let's do text dot delete uh zero and then end so the reason i'm adding this is because now if i go here and i type the wrong password it's gonna delete the text after i read it it's just like a little thing but it's convenient okay so now the next thing we're gonna have to do is create a first time screen so the first time you arrive so first uh first screen let's call it you can call these whatever you want by the way but just make sure if you call these a different thing then when you call the functions like password vault here if you call this let's say password screen you have to change this to password screen okay so then in the first screen what we want to do well uh we kind of wanna we can just copy this to be honest just copy this right even the geometry copy everything here so like all the labels and everything so we don't have to keep rewriting uh we can do like this we can get 250. and then what we want to do is enter uh wait create create master password so this is going to be the screen where you create the master password and then a text entry and then a label which is actually going to say something so the text is equal to re enter password and then another text entry so you put this and you name this text one just in case we need to call it and then the last thing we need is a button so you can just copy this and there you go so button command save password password and text save okay uh actually you know what yeah okay let's uh make this command now or we can't actually run the code yet even though i would like to show you that it's working but either way just to make the function def safe password and then two dots okay so what we're gonna do right now okay we're just gonna print test just so i can show you what the window looks like now so here at the bottom where we put login screen right change it to first script okay then press this and there we go create master password re-enter password and save okay so now one thing we're gonna have to do is in the safe password function we're gonna have to do the first thing we do is if text dot get so if the first text this one is equal to text one dot get so the second text so that means the password they entered are equal and they don't type two different passwords then we just move on and else uh we're gonna be like uh we can change the first label so we can do label dot config and then parentheses text is equal to passwords do not match okay so let's just test it test it out okay so there we go so let's put test test and then let's put pass then it says passwords do not match right here and by the way if you want to make this another label and not change this label then all you have to do is just copy this right here you can put it at the bottom change this take off the text change the name and then you just change from label dot oh sorry from label.config to label two dot config and then it's gonna change it so test test one and then passwords do not match and if we put test test and test then it doesn't show so next thing we want to do is uh actually create the database because basically we have everything working now but we have place folders like the password is equal to test blah blah blah so what we're going to do with the database i'll just explain it before we get into it when we check the password okay actually first when we create the password we're going to go to the database and save the password the user entered so the text.get and then later on when we want to log in we're going to go into the database check what the user entered and check the database and if they match then it's it's gonna work and yeah so yeah let's uh just start doing the database code right now okay guys so uh for the database let's just do this above the actual window let me just add a comment in there she a window okay and then here let's do database code okay so in here what you want to do is with sqlite3 dot and then this is the name of the database you want so i'm going to name mine password underscore vault dot db you have to have db at the end you can name this whatever you want though and then as db so db stands for database by the way and then in here you want to do cursor so cursor is the thing we're going to use to actually control the database then you want to do cursor is equal to db dot cursor with parenthesis so here so now we initiated the database next thing you want to do is uh you want to do cursor dot execute dot execute then parentheses and then what you want to do is put six quotation marks so type the quotation mark button twice and then go in the middle and press enter so you have three on each side okay and then this is important in full caps you type create oh sorry my phone was ringing table if not exists and then you want to type the name of the database that we're going to create i mean of the table so where we're going to store the master passwords let's call it master password and then parentheses and then uh yeah parentheses and then go to the next line so i put another parenthesis and then go to the next line and then in here what you want to do is put id so every table item in the table has to have an id so you put integer so this is like what the id is it's a number so a number is an integer so we have to put this and then you put primary space key so primary key basically means that it's like every different entry in the table will have a different id so it's like the thing that is different between each entry in the table so that's how you differentiate items basically and then you do passwords so this is going to be where we put the master password text and let's put it cannot be known so not no so you can't put no password in here okay so now we created the database so this is creating the database and this is creating a table in the database so we can create multiple of these and uh yeah so next thing you want to do so basically actually let me just explain this basically if this already exists it's not gonna make it but if it doesn't it is gonna make it so it's not gonna stack on top of each other which is what's good okay so now what we wanna do is on the first screen on save password you wanna go to the where we put pass and you want to put insert underscore password so this is going to be a variable is equal to and then the three i mean the six quotation marks again and in the middle in full taps again you type insert into and then not caps the name of the table so master password and then parentheses and then what we want to insert so password and then you can go to the next line and then values so the value we want to insert into password and then put a question mark here i'll explain why later i mean i'll explain right now and then you do cursor dot exa cute and then you can put parentheses and you do insert password like sorry insert password so we're executing this command and then why we put the question mark is that now we do this and in here we put the value of question mark so the reason i put question mark is that later we're gonna have like uh a variable for the password so just make a variable real quick hashed password and just put it equal to let's just do like test one okay and then put this in here because after we're gonna actually take the password and hash it uh so yeah wait actually no don't put it next equal to text one put it equal to text dot get because basically this is gonna so basically what this does is it it's gonna add to the database the password that the user entered into the text when we press submit so yeah and then the next thing you want to do uh you want to go down here you want to go to check password and in the password is equal to txt you want to actually change that so what you want to do is you want to make a new function left get master pass and then two dots and then you want to do check a hashed password so this right now we're not going to hash the password just yet i'll show you how to do it later so just put this equal to text dot get and then you want to do cursor dot execute and then parentheses and then this time only one quotation mark careful don't uh put more select star so this is select all from the table so master password so it's going to select everything from the table and it's going to check where id is equal to 1 and password is equal sorry is equal to question mark so reason uh reason we're doing id is equal to one is because we're not gonna have multiple master passwords it's just gonna be one so where id is equal to 1 and password is equal to question mark and then comma and then square brackets and then circle brackets and then we put the checked hash password in here so basically the question mark is always replaced by the variable you put after and then you want to do return so we return the results so we return cursor dot fetch okay there we go so basically right now it's going to take the password that the user entered while trying to log in and it's going to check for a match so if it has a match so match is equal to get master passwords so then if match and then you can takeoff is equal to text.get so if it has a match then it sends you here and if it doesn't then yeah so now let's run this oh wait actually one thing i forgot to tell you here you can delete this it's going to create a file just delete it it doesn't matter down here what you want to do is you want to do uh so here take this cursor.execute select start from master password take that part copy it down here add quotation mark and parentheses and then what you want to do is you do check is equal to this and then you do if check so if there is something in here in the master password table then you go directly to login screen and if there isn't then you go to the first time screen so basically now we don't have to switch between these anymore it's just gonna detect it so now oh wait one sec line eight line eight uh cursor.execute one sec let me check create table if not exists master password oh uh oh yeah i forgot add a comma right here i bet if you also got the error which you probably did add a comma right after key in the first line just to separate these two okay guys so uh next thing we want to do is uh actually go down here before we run and you can delete this and change this to cursor dot fetch off that was a mistake on my part sorry about that but just yeah change this and then uh right before we go in uh in safe password change in the if statement right at the end you want to do vault i mean password vault so when we save the password it actually brings us to the password vault screen and also right below cursor.execute do db.commit because uh if we don't do this it's not actually going to save in the database and it's just gonna never save okay so now if we run this uh actually wait first let's delete the database delete and then if we run this uh create master password so let's do test test there we go and then if we quit and rerun it it's going to say enter master password test and boom we're in so everything works and now the last thing we're going to have to do is create a hashing script so you want to do def hash password boom there we go and now what you want to do is in the parentheses so this is going to be the input that we get from uh the script that calls this function we're gonna do hash is equal to hash lib so this is the library that actually hashes passwords dot md5 parentheses input so this is going to take the text and turn it into an md5 hash and then we want to take the md5 hash and turn it back into a text so we can actually read it and then uh return hash so that's all we have to do in this function so now what you want to do is uh you can just copy the name go to save password and then hashed password is equal to text.get you want to do hash password parentheses parentheses text i get and also you wanted to dot in code encode and then parentheses quotation mark utf dash eight this is really important because basically we're giving it a string but that actually ha the actual hashing method needs uh the string to be encoded so it won't give it pure string it's going to give it like some weird letters that we can't read as humans but yeah and then you can just copy this go down go to check hash the password and change this so now let's just uh go here and under db.commit let's just print actually now let's do it in the login in the login let's print uh print match match and print uh text no uh print check hashed password and you want to actually put this in here so reason i want to do this is this is going to show us uh what we enter as a hash and this is gonna show us if there's any matches so if we go here right now so wait delete the database actually delete delete and then go here so let's put a password password password and then save and then quit and then go to the login and let's put let's see let's put something random so this is the hash of test but since our password does not test it found no results and it says wrong password but then if we say password so this is the hash of the word password and then because the hash of the word password is equal to the hash of of the database so in the database then uh it works and we get put in the password vault so yeah uh so yeah basically this is what a hash looks like very complicated series of numbers and uh if you have a very long and hard password it's basically gonna take them like years to decrypt there's a website you can probably search it up how long does it take to decrypt my password and then you put your password then there's some that would take trillions of years except if we had quantum computers it will only take like a couple minutes but we're not there yet so uh one thing also i just want to do is here let's do show is equal to star so yeah i told you this at the beginning of the eps uh the tutorial but i'm just going to add it in mine just because it looks better so now when we type the password password it's stars so next episode what we're gonna do is uh we're gonna add uh like grids with uh one grid saying the website one grid saying the username and one grid saying the password so when you log in you're gonna have maybe a plus sign or something it's gonna pop up with like username password website and you enter all of those and then every time you come back there's gonna be all your websites and username and passwords for those websites so basically you forget your facebook password you come here you see your password you forget your steam username you come here you see your username so yeah so this is pretty useful and uh yeah so we'll do this next episode i know this was pretty long but we're using databases and everything uh but yeah so see you guys next episode and i hope you enjoyed the episode just leave me some feedback or some ideas you have in the comments and see
Info
Channel: RaxoCoding
Views: 8,121
Rating: undefined out of 5
Keywords: python, tutorial, python tutorial, python database, sqlite3, hashlib, hashing passwords, passwords managaer, passwords vault, tkinter, intermidiate, python series, coding
Id: UrH2WCoYEVo
Channel Id: undefined
Length: 32min 41sec (1961 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.