Junior — Middle
What authentication methods are you familiar with?
sobes.tech AI
Answer from AI
I am familiar with several authentication methods:
- Basic Authentication — transmitting login and password in HTTP headers (usually via Base64). Simple but not very secure without HTTPS.
- Token-based Authentication — using tokens (e.g., JWT) that the client sends to the server for identity confirmation.
- OAuth 2.0 — an authorization protocol often used for API access via third-party services.
- Session-based Authentication — the server creates a session after user login, and the client stores the session ID in cookies.
For example, in Python with Flask, JWT authentication can be implemented using the PyJWT library:
from flask import Flask, request, jsonify
import jwt
app = Flask(__name__)
SECRET_KEY = 'secret'
@app.route('/login', methods=['POST'])
def login():
username = request.json.get('username')
password = request.json.get('password')
# User verification
if username == 'user' and password == 'pass':
token = jwt.encode({'user': username}, SECRET_KEY, algorithm='HS256')
return jsonify({'token': token})
return jsonify({'message': 'Invalid credentials'}), 401
These are just some methods; the choice depends on security requirements and application architecture.