---
title: "What is Basic Authentication?"  
description: "What is Basic Authentication?"  
author: "ICSM Computer"  
published: 2025-07-27  
updated: 2025-07-27  
canonical: https://www.mindstick.com/interview/34340/what-is-basic-authentication  
category: "authentication"  
tags: ["authentication"]  
reading_time: 2 minutes  

---

# What is Basic Authentication?

[**Basic Authentication**](https://www.mindstick.com/interview/34210/what-are-the-common-authentication-methods-in-rest-apis) is a lightweight authentication scheme based on a username and password to gain access to a resource. It's an HTTP standard and functions by including credentials encoded in base64 with every request.

## How Basic Authentication Works

- A request is sent by the client that includes an Authorization header that appears as follows:

```plaintext
Authorization: Basic base64(username:password)
```

- The server receives and decodes the credentials and checks them.
- If legitimate, the server grants access; else, it sends `401 Unauthorized`.

### Example: Base64 Header

For username: `admin`, password: `1234`\
Base64 encoding of `admin:1234` is:

```plaintext
Authorization: Basic YWRtaW46MTIzNA==
```

### In Code

## Example in C#

```cs
var client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes("admin:1234");
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var response = await client.GetAsync("https://api.example.com/data");
```

Example in **JavaScript (Fetch)**

```javascript
const headers = new Headers();
headers.set("Authorization", "Basic " + btoa("admin:1234"));

fetch("https://api.example.com/data", {
  method: "GET",
  headers: headers
});
```

### Security Note

1. Base64 is **not encryption**, just encoding.
2. Use **HTTPS** always to protect credentials.
3. For better security, consider using **token-based authentication** (like OAuth or JWT) instead.

## Answers

### Answer by ICSM Computer

[**Basic Authentication**](https://www.mindstick.com/interview/34210/what-are-the-common-authentication-methods-in-rest-apis) is a lightweight authentication scheme based on a username and password to gain access to a resource. It's an HTTP standard and functions by including credentials encoded in base64 with every request.

## How Basic Authentication Works

- A request is sent by the client that includes an Authorization header that appears as follows:

```plaintext
Authorization: Basic base64(username:password)
```

- The server receives and decodes the credentials and checks them.
- If legitimate, the server grants access; else, it sends `401 Unauthorized`.

### Example: Base64 Header

For username: `admin`, password: `1234`\
Base64 encoding of `admin:1234` is:

```plaintext
Authorization: Basic YWRtaW46MTIzNA==
```

### In Code

## Example in C#

```cs
var client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes("admin:1234");
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

var response = await client.GetAsync("https://api.example.com/data");
```

Example in **JavaScript (Fetch)**

```javascript
const headers = new Headers();
headers.set("Authorization", "Basic " + btoa("admin:1234"));

fetch("https://api.example.com/data", {
  method: "GET",
  headers: headers
});
```

### Security Note

1. Base64 is **not encryption**, just encoding.
2. Use **HTTPS** always to protect credentials.
3. For better security, consider using **token-based authentication** (like OAuth or JWT) instead.


---

Original Source: https://www.mindstick.com/interview/34340/what-is-basic-authentication

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
