Jump to content

Python file multiple users debugging

1 hour ago, vorticalbox said:

json is universal meaning I could take this data and load into node or c# and still beable to work with the data. it's faster then a txt as you don't have to loop over every line, check if the user names match then check if the password matches.

 

It also stops you have duplicate names as you can only have a key once.

 

 


data[username]

 

 

data is the hash object and username, in this case vorticalbox is the key. JSON is a key value pair.

So how could I add a part that will make a new user.

Specs:

Motherboard: Gigabyte Z97X Gaming 3

CPU: Intel Core I7 4790K

GPU: Gigabyte G1 Gaming GTX 970

RAM: HyperX Fury 16GB

HDD: Seagate ST3000DM001 3TB

SSD: KINGSTON SV300S37A480G 450GB

Cooler: Corsair H100i GTX

Case: NZXT H440 Red

Monitor: DELL U2412M

Keyboard: Gigabyte Force K7

Mouse: Corsair Sabre RGB

 

Link to comment
Share on other sites

Link to post
Share on other sites

49 minutes ago, DerpDiamonds1 said:

So how could I add a part that will make a new user.

Sure you just need to joad the jsom, add the user then save over the file.

 

Though at that point it might be worth looking into a flat file database like sqlLite or tinyDb, which is just a JSON file with functions that make it act like a database

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, vorticalbox said:

Sure you just need to joad the jsom, add the user then save over the file.

 

Though at that point it might be worth looking into a flat file database like sqlLite or tinyDb, which is just a JSON file with functions that make it act like a database

 

Thanks, thats great, but what do all the lines in the functions do? Like 'try:' and 'except:' and 'return check_password(data[username], password)'. Sorry to be a burden, i'm not that familiar with .json in python and would really like to learn.

Specs:

Motherboard: Gigabyte Z97X Gaming 3

CPU: Intel Core I7 4790K

GPU: Gigabyte G1 Gaming GTX 970

RAM: HyperX Fury 16GB

HDD: Seagate ST3000DM001 3TB

SSD: KINGSTON SV300S37A480G 450GB

Cooler: Corsair H100i GTX

Case: NZXT H440 Red

Monitor: DELL U2412M

Keyboard: Gigabyte Force K7

Mouse: Corsair Sabre RGB

 

Link to comment
Share on other sites

Link to post
Share on other sites

23 minutes ago, DerpDiamonds1 said:

Thanks, thats great, but what do all the lines in the functions do? Like 'try:' and 'except:' and 'return check_password(data[username], password)'. Sorry to be a burden, i'm not that familiar with .json in python and would really like to learn.

try and expect is a way for trying the code and if it fails it falls into the except, expect KeyError catches when there is a key error E.G you asked for a key that does exist and the last except catches all other errors

 

you can learn more about error handling here

 

the check_password is a function that returns true if both parameters match and false if they don't then the auth function just returns its output

I like to go for function style in programming, I could have used a lambda function

 


check_password = lambda x, y : x == y

 

though seeing as you're just starting out I thought it best not to throw in anonymous functions you can learn about functional python here

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, vorticalbox said:

try and expect is a way for trying the code and if it fails it falls into the except, expect KeyError catches when there is a key error E.G you asked for a key that does exist and the last except catches all other errors

 

you can learn more about error handling here

 

the check_password is a function that returns true if both parameters match and false if they don't the return just returns the return from the function.

I like to go for function style in programming, I could have used a lambda function

 

 


check_password = lambda x, y : x == y

 

 

though seeing as you're just starting out I thought it best not to throw in anonymous functions you can learn about function python here

Yea i knew about functions, but i didn't see where to put the part that assigns the username to user1 and user2 once they are authenticated (as that is really my main problem). Thanks and sorry to be such a burden.

Specs:

Motherboard: Gigabyte Z97X Gaming 3

CPU: Intel Core I7 4790K

GPU: Gigabyte G1 Gaming GTX 970

RAM: HyperX Fury 16GB

HDD: Seagate ST3000DM001 3TB

SSD: KINGSTON SV300S37A480G 450GB

Cooler: Corsair H100i GTX

Case: NZXT H440 Red

Monitor: DELL U2412M

Keyboard: Gigabyte Force K7

Mouse: Corsair Sabre RGB

 

Link to comment
Share on other sites

Link to post
Share on other sites

37 minutes ago, DerpDiamonds1 said:

Yea I knew about functions, but I didn't see where to put the part that assigns the username to user1 and user2 once they are authenticated (as that is really my main problem). Thanks and sorry to be such a burden.

Oh, I didn't do that part I just did a basic get value and check function.

 

Always good to take the code and adapt it. It's a good way to learn

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

25 minutes ago, vorticalbox said:

Oh, I didn't do that part I just did a basic get value and check function.

 

Always good to take the code and adapt it. It's a good way to learn

Just checking would I go where 'user does not exist' and I would write out the syntax of Jain files, but with their entered username and password?

Specs:

Motherboard: Gigabyte Z97X Gaming 3

CPU: Intel Core I7 4790K

GPU: Gigabyte G1 Gaming GTX 970

RAM: HyperX Fury 16GB

HDD: Seagate ST3000DM001 3TB

SSD: KINGSTON SV300S37A480G 450GB

Cooler: Corsair H100i GTX

Case: NZXT H440 Red

Monitor: DELL U2412M

Keyboard: Gigabyte Force K7

Mouse: Corsair Sabre RGB

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×