Ask coding questions

← Back to all posts
How do I hide the usernames file?
pieninja (6)

So I just added this JSON saving system, and I dont know how to make the usernames file invisible. I dont want people to be able to overwrite others saves, so how can I hide the file?

Answered by LukeWright (287) [earned 5 cycles]
View Answer
Comments
hotnewtop
LukeWright (287)

I don't think you can make env files anymore but you can use databases to read and write keys. the replit database works like your basic python dictionary, so it can be edited by code, but only by people who have edit access to your program. @2plus2is4hoi @pieninja

btfuss (177)

What you can do is make a .env file. on the replit docs they give a tutorial on the .env file and how to use it. It is a file only visible to you, even if someone forks it!

Link to env on replit docs: https://docs.replit.com/repls/secret-keys

pieninja (6)

oh cool! would json still be able to write and read from [email protected]

btfuss (177)

@pieninja
To make the JSON into a string use this python command: json.dump(whatever). Then, store that string into a variable, and write that into a .env file. Also, I found this on github: https://gist.github.com/kr/6161118. Another thing that is helpful, is if you need to get the .env variable, then just use:
import os secret_token = os.getenv("TOKEN"). Remember, refer to https://docs.replit.com/repls/secret-keys for extra information, because I may have not listed everything!

You're welcome if I solved your question!

btfuss (177)

@robowolf
you could also save the stuff in REPLDB as @LukeWright kinda referenced

robowolf (549)

@2plus2is4hoi Yeah, but encryption feels cooler.

robowolf (549)

@2plus2is4hoi The amount of pings is .... is almost frightening

btfuss (177)

@robowolf a man of culture i see, @robowolf = god?

pieninja (6)

ok i did it using repl.it database. can you guys test it out to make sure it works? (do farming for 5 seconds to get to saving) @robowolf @2plus2is4hoi

robowolf (549)

@pieninja We cant access your database. Any keys made would be saved to our database. If you want a database containing all users, encryption outside of secret variables is easier because it makes it harder for people to read your code but it is still usable. Pickle is also a good option.

pieninja (6)

so it wont work for you? @robowolf

robowolf (549)

@pieninja Theoretically it will. It's just everything will be saved locally.