#🔒 so im trying to code a password tester and a username tester

34 messages · Page 1 of 1 (latest)

obsidian prawn
#

I’m trying to code a login system. I already built a password tester and a username tester, and they work. Now I want to add a feature where the user can log in, and if they don’t already have an account, it should allow them to create one.

login = input('please login, if you dont have a account please create a account')

username = input('please make a username ')
password = input('please make a password ')
strong_symbol = '!!'
mediocure_symbol = '@'
# username creater
if username.upper:
      print('good username')
else:
      print('please add a capital letter')

# password creater
if '!!' in password:
    print('strong password')
elif '@' in password:
        print('mediocure password')
else:
       print('weak password, please add either the @ or !!')```
warm anvilBOT
#

@obsidian prawn

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

old ginkgo
#
if username.upper:

This is broken, btw. upper is a function, so it needs to be called. You're checking if the function itself is true, which it always will be.

#

Also, that will uppercase the string, not check if it's upper.

#

You want isupper()

obsidian prawn
#

oh huh didnt show a error it works

#

ill change it

old ginkgo
# obsidian prawn oh huh didnt show a error it works

That's why it's important to test your code. The code is valid, it just doesn't do what you intended.

If you're going to have a check that checks if the username is uppercase, as part of your testing, you should have given it a string that you expected would cause "please add a capital letter" to print out.

#

You would have found that it's impossible for that to be printed.

obsidian prawn
#

well im testing it and it works \

#

i know its wrong but it worls

#

its seeing that i added a uppercase and its printing it out

old ginkgo
#

It doesn't work if it doesn't do what you expected. Again, "please add a capital letter" would never print in your original code, and it's unlikely that that was intentional.

#

As part of testing, you need to make sure all the code works and not just a single execution path. That's important, because if the input ever changes to something other than what you tested, you have no idea what your program will do.

obsidian prawn
#

oh i see my bad

#

so i know i need a database but i never did that before

#

what i understand is that you cant import like a regular module

#

right?

old ginkgo
#

You don't technically need a full database, but that is the best solution to storing data. Have you ever used open before to read/write files?

obsidian prawn
#

yes

#

oh i see so i would either make a text file then do file.open and do write or read

old ginkgo
#

But ya, use open to write information when they create an account, and read the file to see login information when they want to log in.

obsidian prawn
#

well i have used txt files in my code before but never made a database before

old ginkgo
#

If you're confident that it's not worth trying to use a text file here, then you can go straight to using a database. For this, just use sqlite, which comes with the Python standard library.

obsidian prawn
#

so i would import it?

old ginkgo
#

SQLite is far easier to manage than enterprise-ready databases managers which require servers.

old ginkgo
# obsidian prawn so i would import it?

You import the library, yes. Then use the library to create a database file. Give this whole section/page a read over: https://docs.python.org/3/library/sqlite3.html#tutorial

Python documentation

Source code: Lib/sqlite3/ SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard ...

#

Ok, maybe not the whole page. Definitely the tutorial section, though.

obsidian prawn
#

ok so i would import it then make a cursor then make a table then add the username and password into it?

#

or do i have it backwards would i make the table first or the cursor

old ginkgo
warm anvilBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.