Articles

Authentication vs Authorization vs Encryption

Authentication, authorization, and encryption are all key concepts in web security, but it’s easy to confuse them. In this article, you’ll learn what these concepts are and what roles they play in web security.

Let’s start by understanding what authentication is and how it works.

  • In this course, you'll learn how to implement User Authentication and Authorization in an Express web application.
    • Intermediate.
      5 hours
  • Learn how to defend against malicious attacks and improve user experiences using sessions, cookies, and password authentication.
    • Includes 5 Courses
    • With Certificate
    • Intermediate.
      8 hours

What is authentication?

Authentication is the verification of who you are. For example, let’s say you’ve gone to a concert. At the front door, the security guard asks to see your ticket and ID in order to verify that the name on your ID matches the name on your ticket. This is an example of authentication.

Authentication relies on one or more factors to verify identity, and these factors come in three main types:

  • Knowledge is something you know, like a username and password.
  • Possession is something you have, like a security card or mobile device
  • Inherence is something you are, which generally refers to biometric data such as fingerprints.

Note: There are additional factors, such as location and time, that can be used to complement existing factors but are generally not suitable for authentication on their own.

Authentication that relies on a single factor, such as a simple username/password combo, is called single-factor authentication, and is becoming increasingly insecure.

An image showing that the user only needs a password to log in to the website, demonstrating single-factor authentication.

Authentication that requires multiple factors, such as a username/password combo and a code sent to a mobile device, is known as multi-factor authentication. This is distinct from multi-step authentication, which requires multiple types of authentications within a single factor, such as a password and a PIN.

An image showing that the user needs a password, a code sent to their phone, and that same code inputted into the website before they can gain access, demonstrating multi-factor authentication.

Next, let’s discuss authorization and its importance in web security.

What is authorization?

Authorization is the verification of what you are allowed to do. Returning to our concert example, once the security guard has authenticated you, you then give your ticket to a different security guard, who then only allows you to pass into General Admissions (instead of the VIP section). This is an example of authorization.

Authorization is very important for web security, and it is responsible for everything from preventing users from modifying each other’s accounts, to protecting back-end assets from attackers, to granting limited access to external services.

Good authorization will allow you to limit users and services to the privileges they require; just because a user is authorized to manage one group doesn’t mean they should be able to manage all groups, for example.

With authentication and authorization covered, it’s time to move on to encryption.

What is encryption?

One of the core tools for enforcing authentication and authorization is encryption. Encryption is the process of transforming data into a format that is unreadable unless you have the correct key to decrypt it. Encryption comes in two main types:

An image showing the sender and recipient encrypting and decrypting with the same key, demonstrating symmetric encryption.

Symmetric encryption makes use of the same key to encrypt and decrypt data.

An image showing the sender using one key to encrypt the data and the recipient using a different key to decrypt the data, demonstrating asymmetric encryption.

Asymmetric encryption uses separate keys for encryption and decryption.

Lastly, let’s take a look at the differences that make authentication, authorization, and encryption three distinct concepts in web security.

Authentication vs authorization vs encryption

Here are the differences between authentication, authorization, and encryption:

Feature Authentication Authorization Encryption
Definition Verifies identity Grants or denies access Protects data by making it unreadable
Answers “Who are you?” “What can you do?” “How is your data kept safe?”
Process Login (passwords, biometrics, MFA) Role/permission check Applying cryptographic algorithms
Order Happens first Happens after authentication Can happen before, during, or after authentication/authorization
When to use When you need to confirm user identity When you need to enforce access control When you need to protect sensitive data from being exposed

Conclusion

Authentication, authorization, and encryption are distinct but related concepts within cybersecurity, and all three are important for maintaining a secure environment. Authentication determines identity, authorization determines the privileges associated with an identity, and encryption ensures that data can only be accessed by authorized parties.

If you want to learn more about implementing authentication and authorization in a web application, check out the User Authentication & Authorization in Express course on Codecademy.

Frequently asked questions

1. What is authorization vs. authentication?

  • Authentication verifies identity (e.g., logging in with a password).
  • Authorization determines access rights (e.g., viewing vs. editing a document).

2. Is OTP authentication or authorization?

An OTP (One-Time Password) is a type of authentication because it confirms the user’s identity.

3. Is OAuth authentication or authorization?

OAuth is primarily an authorization framework. It lets users grant third-party apps limited access to their resources without sharing their credentials.

4. What is the purpose of authorization?

The purpose of authorization is to enforce access control policies, ensuring users can only perform actions or view data they are permitted to.

5. What are the 5 types of authorization?

The main 5 types of authorization are:

  • Role-Based Access Control (RBAC): Access based on predefined roles.
  • Attribute-Based Access Control (ABAC): Decisions based on user attributes, environment, or context.
  • Policy-Based Access Control (PBAC): Access granted based on organizational policies.
  • Rule-Based Access Control: Access granted based on specific rules (e.g., time, location).
  • Discretionary Access Control (DAC): Owners of resources decide who can access them.
Codecademy Team

'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

Meet the full team

Learn more on Codecademy

  • In this course, you'll learn how to implement User Authentication and Authorization in an Express web application.
    • Intermediate.
      5 hours
  • Learn how to defend against malicious attacks and improve user experiences using sessions, cookies, and password authentication.
    • Includes 5 Courses
    • With Certificate
    • Intermediate.
      8 hours
  • Learn how to add user sign up, login & logout functionality to your Rails applications.
    • With Certificate
    • Intermediate.
      3 hours