Share your repls and programming experiences

← Back to all posts
Username and Password
chiliconco (34)

I am new to python and i programmed this. It took me quite a while. It may not be much but I am proud of it! Do you have any ideas on what I could implement this into in the future?

Thanks for taking the time to check this out :)


P.S If there are any errors PLEASE let me know!!


1.1 - Fixed capital letter error upon signing up/logging in.
1.2 - Fixed whitespace error upon signing up.
1.3 - If login/sign up is mistyped, the script now re-asks the question.
1.4 - Improved naviagtion
1.5 - PASSWORDS NOW HASHED! All credit goes to @Coder100 for helping me out
immensely with this! :)

Coder100 (450)

This is a great program!
You probably want to encrypt the passwords though...

chiliconco (34)

@Coder100 Thank you! Encrytion is the next step after I fix some other problems with signing up. :)

Coder100 (450)

Good luck!
Do you want any help with encryption? @chiliconco

chiliconco (34)

@Coder100 Yes please, that would be great! I have been trying to wrap my head around it for a while but it didn't make much sense to me. Some help would be greatly appreciated, thank you :))

Coder100 (450)

Until I go onto computer, try converting the hash function in this project: on line 376. (It’s on the client.js file in the public folder) @chiliconco

Coder100 (450)

I will convert it for you as soon as I can. Good luck! @chiliconco

chiliconco (34)

@Coder100 Thank you so much! I will try and convert the hash as soon as I can. But I do not have access to a computer at the moment so I will get back to you tomorrow. Thanks! :)

Coder100 (450)

Ok I did it! View the code and proofs involving the code here:
EDIT: This works for everything except for special characters, like 我会说中文
Feel free to make it better!

chiliconco (34)

@Coder100 wow! Nice work, thank you very much :)

chiliconco (34)

@Coder100 Hi there your hashing tool is very helpful but I seem to have ran into an error, whenever I try and change the text that is going to get hashed I get this error:

Traceback (most recent call last):
File "", line 41, in <module>
print(hash("Hello World!")) File "", line 22, in hash indx += ord(str(i))TypeError: ord() expected a character, but string of length 2 found


Coder100 (450)

Yes, i see this problem, and I think maybe this might work: line 22: indx += ord(str(i[0])) maybe....? Try it out!

Also, are you doing the hackathon? @chiliconco

chiliconco (34)

@Coder100 Thank you, and no I am not doing the hackathon but there is still an error with the code :(

Traceback (most recent call last):
File "", line 41, in <module>
print(hash("hello world"))
File "", line 22, in hash
indx += ord(str(i[0]))
TypeError: 'int' object is not subscriptable

Thanks so much for your help! :))

Coder100 (450)

Ok, make a loop that goes through ‘i’ then split it up into an array, then do what I did. Good luck! @chiliconco

Coder100 (450)

You’re welcome! Does it work now? I didn’t test it @chiliconco

chiliconco (34)

@Coder100 Sorry I couldnt get back to you earlier, I was in class, thanks!!! :)

chiliconco (34)

@Coder100 Just tested it, it works PERFECTLY! Do you know of any tutorials that could help me dehash the password for when the user logs in? Thank you!! :))

Coder100 (450)

No, you don't really dehash, but instead, you encrypt what the user typed in and then see if it matches the password that was saved, because the encryption method, however complicated it is, is always constant. @chiliconco

chiliconco (34)

@Coder100 Yes, your right I didn't think of that, fixing it now :)

Coder100 (450)

Ok, good luck! If you have any more errors, contact me and I'll get to work! @chiliconco

chiliconco (34)

@Coder100 It works completely now :) Thanks!!

DJWang (437)

Wow! Very impressive! However, trying to type In "sign up" with all the capital letters is very annoying. For example, do something like this instead:

print('Hello! What would you like to do?')
print('1. Sign Up')
print('2. Log In')
loginsignup = input('>>> ')
Then all your code down.

Very impressive! I've just started to learn about txt files, and this game can be put to very good use! Great job!

-DJStudios Team

chiliconco (34)

@DJWang Thank you for your kind words, I have taken on board what you said and modified the script so it is not case sensitive :) Many thanks

DJWang (437)

@chiliconco No Problem! The code looks much simpler and the game is better! Keep up the good work! :)


DJWang (437)

@chiliconco :) You're a great coder!

syc1 (3)

@DJWang or, more conveniently, just convert the input to all lowercase

chiliconco (34)

@syc1 that is what I did to fix the code.

IlyaMikheev (9)

We will never know the truth...

druceb (11)

@IlyaMikheev I had this error, they claimed to have fixed it but it is still an error

ManharRavipati (38)

great job you should use this in a game!

chiliconco (34)

@ManharRavipati Yes, perhaps I could get users to create an account so I can save a highscore for them on a leaderboard? :)

ballpointcarrot (1)

This looks like a great start, and it looks like you had fun putting it together, which is the most important thing!

I'll try to start with quick and easy suggestions, and then work up to some more challenging ideas.

First, let's take a look at this section (Lines 12-13):

x = 0
while (x == 0):

Since x == 0 evaluates to True (you can check this in the Python prompt), you can replace this check with the following:

while True:

That way, you don't need to create an extra variable to store this value to check it!

Second, let's look at your email checker. There's some values that can pass your checking, but may not be valid email addresses:

You can make your email checker look at more details, but email checking is hard. For example, here is a talk on Youtube showing how hard it is to tell what is and isn't a valid email address (some of them are surprising!).

What I would do here to start, is take your email checker code (lines 15-17) and move it into its own function:

def is_email(email):
    return ((email.find("@") > -1) and
                (email.find('.") > -1) and
                # more checks that you need

# later on:
if is_email(email):
    print("Invalid Email."))

This will let you expand on the way you handle the email checker, while making the check itself easy to read. Making sure your code is easy is important! It makes it so others looking at it understand what your code is trying to do.

Eventually, your email checker function will become really hard to manage by having a lot of checks in it. A more advanced way of checking an email is to use a Regular Expression, or RegEx. This is a type of language used to define different types of characters, and look at how they match text provided against it.

A common regex used for email (which isn't 100% correct itself!) looks like this:

r"(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"

Finally, it's unsafe to store passwords in a file directly. Think about what could happen if someone were to get a copy of that file - they would have everyone's emails and passwords for this system. The best way to avoid this and keep your system secure is to not store the password at all.

But how do you make sure the password is correct if you're not storing the password?

Instead of storing the password, we can store a mathematical value that represents the password. If we take the password in, run the math against it, and make the same value as the stored value, we can say that the two passwords are the same. This is called cryptographic hashing.

Python provides a library called hashlib that can provide some of these hashing functions. This is another hard problem that could be fun to work on.

Let me know if you have any questions, and I'll try to help where I can. :D

chiliconco (34)

@ballpointcarrot Wow! Thank you for this contribution, I will get to work on the email def as soon as I have a chance (I am fixing other problems people have brought up at the moment), @Coder100 has helped me out ALOT with the hashing and I will be trying to implement that later. Thank you so much! :)

MasonCollinson (1)

Hello @chiliconco, Maybe try to make it so then if someone spells something wrong in the initial log in/sign up question, it repeats the question instead of assuming they mean log in. If that makes sense.

chiliconco (34)

@MasonCollinson Ah right, this is a really good idead :) I will edit the code as soon as I can. Thank you!

ChezCoder (83)

The problem is, since you are using split(), the user can mess up the system by making an email or password with a whitespace. This can make the split() function return faulty email or password combinations. Either write the email and password with a separator like | or make the user redo the email or password if it contains a whitespace.

chiliconco (34)

@ChezCoder Thank you for bringing this problem to my attention, I will fix it ASAP! :)




Hello, some things to know:
1. Don't store passwords in plaintext (passwords.txt file)
2. for the "login" and "signup" stuff, you can check user input and then check .tolower.charAt(0) to see which one it corresponds to

chiliconco (34)

@sanjaykdragon Do you suggest i look into python encrytion then? Also I will take a look at the login and sign up stuff and improve it. Thank you :)


@chiliconco encryption is useless, look at hashing

PowerCoder (105)

Also, the passwords and usernames don't save. I suggest that you somehow save them. Maybe you could use json_store_client, but then it would be visible to everybody. Maybe you could somehow hide the key.

chiliconco (34)

@PowerCoder I will look into json_store_client and then get back to you with my progress. Thank you!

chiliconco (34)

There is an error in this (Login failed/Login successful), I know what is causing it, now I just need to find a way to fix it. Thanks for letting me know!

DJWang (437)

Hmm… Looks like something went wrong there!

Apple05222 (0)

I did it, but I got a "Login Failed." followed with "Login Succesful"

p.s. Succesful is spelled wrong. (Successful) I don't mean to make you feel bad but, just to let you know.

chiliconco (34)

@Apple05222 haha, no bad feelings :) your problem seems to be common but I cant find what is wrong. I will have a look later. Thanks!!

JohnStarrs (23)

is this python turtle or normal python?

JohnStarrs (23)

@chiliconco thats really cool for your first code

pieromqwerty (22)

I signed up, and then i got two outputs:

Login Failed.
Login Succesful!

lmao, task failed successfully!

chiliconco (34)

@pieromqwerty Hmm, I fixed this earlier and now it is working fine for me. Strange.

druceb (11)

Whenever i log in it says login failed and then login successful. After this the program ends

chiliconco (34)

@druceb I fixed this earlier, I musn't of saved it, I will fix it now :)

JideOlatunji (8)

hello my name is jide how are you

chiliconco (34)

@JideOlatunji I am good, how are you? :)

chiliconco (34)

@JideOlatunji ah right, I hope you get better soon