Add signup/login to your app
Anvil has a built-in user management system that makes login and permissions easy.
Follow this quickstart to set up a signup/login form (user authentication).
Log in to Anvil and click ‘New Blank App’. Choose the Material Design theme.
In the App Browser, click the + next to Services.
You’ll see a list of available services and integrations. Click on Users.
Under Forms in the App Browser, select Form1.
Click on the ‘Code’ tab to see the Python code for
You will see a few lines of pre-written code. Your Form is represented as a class called Form1. It currently has
only one method, the
At the end of the
__init__ method, write this line:
Now click the ‘Run’ button at the top of the screen.
Your app will display a login form.
Sign up and verify your email address, then stop the app to return to the editor. (You may have opened the app in a new tab when you verified your email, in which case close that tab, then stop the app in your original tab.)
Click on Data Tables under Services in the App Browser.
You should see a table called Users, containing one row - the user record for the email address you signed up with.
Notice that your password has been hashed by Anvil (using the bcrypt algorithm). This means somebody with access to the data stored within Anvil cannot work out your password. It is the standard best-practice way to store passwords on the web.
Add this line to the end of the
__init__ method in
print('This user has logged in: ' + anvil.users.get_user()['email'])
This will get the logged-in user and print that user’s email address.
Run your app and log in. You will see your email address printed in the Output Panel.
Click on the button below to clone a finished version of this app into your account.
The app you’ve built creates new user accounts based on email addresses. You can also enable buttons to log users in with their existing accounts in third-party services and other systems:
Here are the built-in options:
- Google accounts
- Facebook accounts
- Microsoft accounts (Skype, Office 365 etc.)
- Accounts in your own Microsoft Azure Active Directory tenant (on the Business plan)
- Accounts in your own local Active Directory (on an Enterprise plan)
- X.509 certificates (on an Enterprise plan)
Want more depth on this subject?
Read more about User authentication and authorisation.
Want another quickstart?
Every quickstart is on the Quickstarts page.