0Pricing
Django Academy · Aula

O modelo User e authenticate()

Verifique credenciais com o usuário integrado

O modelo User e authenticate() é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

You Already Have Users

Django ships a full User model out of the box, so you never write account tables by hand. It stores usernames, hashed passwords, and more. 👤

Where the User Lives

The model sits in django.contrib.auth, an app that is enabled in fresh projects. Import it and the whole auth toolkit comes along.

from django.contrib.auth.models import User

Key User Fields

Each user has a username, plus email, first_name, and last_name. These are the everyday fields you read and display in your app.

Passwords Are Never Plain

Django stores a salted hash of every password, never the raw text. Even you, the developer, cannot read a user's actual password. 🔒

Create a User Safely

Use create_user so the password gets hashed for you. Setting the password by hand would store it in the clear.

User.objects.create_user(username="ada", password="secret123")

Meet authenticate()

The authenticate() function checks a username and password against the database for you. It is the heart of every login flow.

from django.contrib.auth import authenticate

How authenticate() Works

Pass it the credentials and it returns the matching user object when they are correct. No hashing or lookups for you to write.

user = authenticate(username="ada", password="secret123")

When Credentials Fail

If the username or password is wrong, authenticate() returns None. Always check for that before treating the user as logged in.

if user is None:
    print("Invalid credentials")

Active Users Only

The is_active flag lets you disable accounts. By default authenticate() refuses to return inactive users, blocking banned logins.

Staff and Superusers

Two extra flags matter: is_staff grants admin-site access, and is_superuser grants every permission. Most users have neither.

Authenticate Is Not Login

Remember: authenticate() only verifies identity. It does not start a session, so the user is not yet logged in after this call.

Quick Check

What does authenticate() return when the password is wrong?

Recap: Users and Identity

You met Django's built-in User model and used authenticate() to verify credentials. Passwords stay hashed, and a failed check gives None. ✅

Perguntas Frequentes

A aula “O modelo User e authenticate()” é grátis?

Sim — o texto completo de “O modelo User e authenticate()” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.

O que vou aprender em “O modelo User e authenticate()”?

Verifique credenciais com o usuário integrado Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Django Academy?

Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “O modelo User e authenticate()”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Django Academy?

Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O modelo User e authenticate()
  2. login, logout e visualizações de autenticação
  3. Registro com UserCreationForm
  4. login_required e proteção de visualizações
← Voltar para Django Academy