Learn to Code via Tutorials on Repl.it!

← Back to all posts
How To Use Repl's Database
MikeJMS8910 (160)

Repl.it has its own way of saving information called Repl Database. It is very easy to use and is great for making Log In Systems. In this tutorial, you will learn how to use repl's database by making a login system.

Before you can start using its functionality you will need to import it. You can do that by putting in

from replit import db

this will then install the database into your code.

The next thing you would want to do is create an area yourself where the user will be able to type in what they want their username or nickname to be. Have an input variable for what they decide to use. Next, you will need to add that input variable to the DB.

username = input()

Now, let's add a value that we want to save to this user.

value = input()
db["username"] = "value"

You can make the value anything you want. It could be money, coins, XP, etc. As you can see that when we set the keys they are the same as the input names.

Now that we have a way of creating an account now let's be able to log in.

LogUser = input()
GetValue = db["LogUser"]

Now we have a way of getting the user's value. You can implement this however you would like.

Comments
hotnewtop
PrinceOfHeaven (1)

Pretty good! I like the idea and I'm trying to use a log in system in a game I'm creating. Could you tell me how to implement username and password system?

bigboyyyyyyyy69 (5)

@PrinceOfHeaven I know this is a late response but I found this cool so I went ahead and made a SIMPLE example of this..
check it out here

MikeJMS8910 (160)

@bigboyyyyyyyy69 yea cool. What I did when I made my stuff is made the username a key, the password a value and then the password also a key to save user information

bigboyyyyyyyy69 (5)

@MikeJMS8910 epic, I made this earlier tbh idk if I did that or not but none the less it works, although would you happen to know any db error handler code such as on key not found or smth (whatever it is obvi that code wont work).. it's good for checking if user exists like the example I put rather than just trying for an exception since an exception could be raised due to another error in the code.

PrinceOfHeaven (1)

[email protected] @MikeJMS8910 but as you know something do not have repl database. I want to do something like this on pycahrm. Do you know how?

MikeJMS8910 (160)

@PrinceOfHeaven the only other one that I learned was pickle and repls db

bigboyyyyyyyy69 (5)

@PrinceOfHeaven nah idk how to use pycharm tbh but u can use that code to implement it.

RhinoRunner (866)

I like it, but you probably should use markdown to make your post a little bit better (such as putting 3 backticks before your code)