Authentication answers one question: who is making this request? In a backend internship you will meet three common answers: a server-side session, a signed token, and an API key. Learn what each proves, where it is stored, and how it fails, then build one small login flow and handle passwords with a strict checklist.
This guide is for Rayat Bahra University students who want to be useful in a two-week backend internship. It moves from concepts to a comparison table, a minimal Python login sketch, a password-safety checklist, and a 14-day plan. If you want a structured, free place to practise, the free two-week online internship from CareerSwami offers 26 tracks, a free offer letter and a free completion certificate after successful completion.
Authentication versus authorization: the distinction interns blur
Authentication verifies identity. Authorization decides what that identity may do. A login form is authentication. A rule such as “only the owner can delete this order” is authorization. Most real bugs live in the second one, because developers verify the user and then forget to check ownership.
- Authentication (AuthN): “You are student ID 42.” Evidence: password, one-time code, signed token, key.
- Authorization (AuthZ): “Student 42 may read their own marks but not edit them.” Evidence: roles, permissions, ownership checks.
- Status codes: 401 means “I don’t know who you are” (missing or bad credentials). 403 means “I know who you are, and you may not do this.”
How a login actually works, step by step
- The client sends a username and password over HTTPS.
- The server looks up the user and compares the submitted password against a stored hash, never a plain password.
- If it matches, the server issues proof of login: a session ID, a token, or nothing at all (API keys are issued earlier, out of band).
- On every later request the client presents that proof.
- The server validates the proof, identifies the user, and then runs authorization checks.
Steps 3 to 5 are where sessions, tokens and API keys differ.
Free 2-Week CareerSwami Internship
Online, 14 days, with a free offer letter and a free completion certificate once you finish the work. Check with your college that it fits your requirement before you enrol.
Sessions, tokens and API keys compared
| Aspect | Server-side session | Signed token (e.g. JWT) | API key |
|---|---|---|---|
| What the client holds | Random session ID, usually in a cookie | Self-contained signed string with claims | Long random string tied to an app or account |
| Where state lives | Server (memory, database, Redis) | Mostly in the token itself | Server keeps the key (ideally hashed) and its metadata |
| Best suited to | Browser-based sites with server-rendered pages | APIs used by mobile apps or single-page apps | Server-to-server calls, scripts, third-party integrations |
| Identifies | A logged-in person | A logged-in person (or service) | Usually a program or project, not a person |
| Revoking access | Easy: delete the session row | Harder: wait for expiry or keep a denylist | Easy: delete or rotate the key |
| Typical weakness | Session fixation, missing cookie flags, CSRF | Long expiry, weak signing secret, secrets placed in the payload | Keys committed to GitHub, shared in chats, never rotated |
| Scaling note | Needs shared session storage across servers | Stateless validation, but revocation needs extra design | Needs rate limits and per-key permissions |
Which one should you pick?
- Building a classic website with login pages: start with sessions. They are simple and revocable.
- Building an API for a mobile app: short-lived access tokens, often with a refresh mechanism.
- Letting another program call your service: an API key, scoped to the minimum permissions and rate limited.
- Unsure: sessions are the safest default for a beginner project because the server stays in control.
A minimal login example in Python (illustrative)
The sketch below is illustrative teaching code. It has not been executed here, and a production system should use a vetted framework (Django, Flask-Login, FastAPI security utilities) rather than hand-rolled logic. It uses only the standard library so the ideas are visible.
import hashlib, hmac, os, secrets, time
USERS = {} # username -> (salt, hash)
SESSIONS = {} # session_id -> (username, expires_at)
def hash_password(password, salt=None):
salt = salt or os.urandom(16)
digest = hashlib.scrypt(password.encode(), salt=salt,
n=2**14, r=8, p=1)
return salt, digest
def register(username, password):
if len(password) < 10:
raise ValueError("password too short")
USERS[username] = hash_password(password)
def login(username, password):
record = USERS.get(username)
# same generic failure whether user or password is wrong
if not record:
return None
salt, stored = record
_, attempt = hash_password(password, salt)
if not hmac.compare_digest(stored, attempt):
return None
sid = secrets.token_urlsafe(32)
SESSIONS[sid] = (username, time.time() + 1800) # 30 minutes
return sid
def current_user(sid):
entry = SESSIONS.get(sid)
if not entry or entry[1] < time.time():
SESSIONS.pop(sid, None)
return None
return entry[0]
def logout(sid):
SESSIONS.pop(sid, None)
What each part is doing
- scrypt with a random salt: a deliberately slow, salted hash, so identical passwords produce different stored values and brute force is expensive. Argon2 or bcrypt via a maintained library are equally reasonable choices.
- hmac.compare_digest: a constant-time comparison that avoids leaking information through timing.
- secrets.token_urlsafe: a cryptographically secure random ID. Never use
randomfor security values. - Expiry and logout: sessions end on a timer and on request.
- Missing from the sketch: HTTPS, rate limiting, account lockout, CSRF protection, persistent storage and cookie flags. Name these gaps in your report; that shows maturity.
Turning it into a web endpoint
When you wrap this in Flask or FastAPI, send the session ID in a cookie marked HttpOnly, Secure and SameSite=Lax (or Strict). Return the same message for “unknown user” and “wrong password” so attackers cannot enumerate accounts.
Worked illustration: choosing an approach for a campus event portal
This scenario is invented for teaching. Suppose you build a small event-registration service with three kinds of callers: students using a website, a mobile app for volunteers, and a script that pushes attendance data from a gate scanner.
| Caller | Mechanism | Reasoning | Safeguards |
|---|---|---|---|
| Students on the website | Server-side session in a cookie | Server-rendered pages, instant logout, easy revocation | HttpOnly, Secure, SameSite cookie; 30-minute idle timeout; CSRF token on forms |
| Volunteer mobile app | Short-lived access token plus refresh token | No cookie jar; app calls the JSON API directly | 15-minute access token; refresh token stored in the platform keystore; rotate on use |
| Gate scanner script | API key | A machine, not a person; no interactive login | Key limited to the attendance-write endpoint; stored hashed server-side; rotated each term; kept in an environment variable |
Notice the authorization layer on top: a volunteer token can mark attendance but cannot export the full student list, and the scanner key cannot read anything. Writing that matrix down before coding is a habit worth showing your mentor.
Password-handling security checklist for interns
Use this as a pre-commit and pre-submission review. Every line should be answerable with yes.
Storing and verifying passwords
- Passwords are hashed with a slow, salted algorithm (Argon2, bcrypt or scrypt), never MD5, SHA-1 or plain SHA-256 alone.
- No plain-text or reversibly encrypted passwords exist in the database, logs or backups.
- A minimum length is enforced (10 or more characters is a sensible floor), and long passphrases are allowed.
- Comparison uses a constant-time function.
- Login failures return one generic message.
- Repeated failures trigger rate limiting or temporary lockout.
Transport and sessions
- Every login and authenticated endpoint is served over HTTPS only.
- Session IDs and tokens come from a secure random generator.
- Cookies carry HttpOnly, Secure and SameSite attributes.
- Sessions expire and are destroyed on logout and password change.
- Tokens have short lifetimes and a signing secret that is long and random.
Secrets and logging
- No passwords, API keys or signing secrets in source code, screenshots, README files or chat messages.
- Secrets are loaded from environment variables or a secrets manager;
.envis in.gitignore. - Logs never include passwords, full tokens or full request bodies from login routes.
- If a key was ever committed, treat it as leaked: revoke and rotate it, because deleting the commit is not enough.
- Test accounts use throwaway passwords, never your real email or college credentials.
Authorization follow-through
- Every route states who may call it, and the check happens on the server.
- Object-level checks confirm the record belongs to the caller.
- Error messages do not reveal stack traces or database details.
Mistakes that quietly break authentication
- Storing the JWT payload as if it were secret. Payloads are encoded, not encrypted; anyone can read them.
- Accepting unsigned or “none” algorithm tokens. Pin the expected algorithm when verifying.
- Putting tokens in URLs. They leak into browser history and server logs.
- Trusting client-side checks. Hiding a button is not access control.
- Inventing your own crypto. Use library functions for hashing, signing and random values.
- Sharing one API key across every service. One leak then exposes everything.
Rayat Bahra University: Fitting an Authentication Project into a B.Tech Backend Internship
Rayat Bahra University is a private university in Greater Mohali, Punjab. Its official website gives the campus address as Sahauran, Tehsil Kharar, District Mohali, and says it was established in 2014. The university FAQ adds that it was set up by the Rayat Bahra Group and is recognised by the UGC, with professional programmes needing council approval where applicable.
For a student building login, password-hashing and token features during a backend internship, the useful detail is how the university treats practical work. The FAQ states that internships, live projects and industrial training are integrated into the curriculum. It does not give a duration, a semester or a credit value, so a student cannot assume a particular internship or authentication project counts in a given semester without asking.
The same FAQ describes a dedicated Training & Placement Cell that focuses on employability, internships and final placements, with aptitude tests, soft skills, interview preparation, technical workshops and resume building. The placement highlights page describes a Finishing School and pre-placement boot camps. That page itself tells students to verify recruiter and placement claims on official university pages, which is sensible advice, since headline figures on promotional pages are not a guarantee for any individual student.
The B.Tech Computer Science & Engineering page shows a four-year, eight-semester programme with eligibility of 10+2 including Physics and Mathematics, or an eligible diploma route. Course-level detail, such as which semester covers databases, web development or security, is not on that page, so the department syllabus remains the authority on what authentication topics are already taught and what a project can add.
Practical checks for a student doing an authentication-focused backend project
- Ask the department which semester carries the industrial training requirement and how many weeks it expects.
- Get the current syllabus for your specialisation and note which database, web or security papers overlap with your project.
- Ask the Training & Placement Cell whether a company offer letter must be registered before the internship starts.
- Confirm who evaluates the final report and whether a working demonstration is expected.
- Never build the project on real student data, and ask your supervisor to approve the test accounts you use.
A 14-day plan for learning authentication in a backend internship
| Days | Focus | Deliverable |
|---|---|---|
| 1-2 | HTTP basics, cookies, headers, status codes 401 and 403 | Notes plus a small route that reads and sets a cookie |
| 3-4 | Password hashing and registration | Register endpoint with salted slow hashing and length rules |
| 5-6 | Session login, logout and expiry | Working login flow with secure cookie flags |
| 7-8 | Token-based login with short expiry | Token issue and verify endpoints; note on revocation limits |
| 9 | API keys for a machine client | Scoped key stored hashed; one protected route |
| 10-11 | Authorization: roles and ownership checks | Permission matrix and tests for forbidden access |
| 12 | Rate limiting and generic errors | Throttled login route |
| 13 | Run the checklist, scan the repo for secrets | Completed checklist with fixes |
| 14 | Write-up and demo | README with design choices, known gaps and next steps |
What to put in your final report
- A one-paragraph explanation of why you chose sessions, tokens or keys for each caller type.
- The permission matrix.
- The ticked checklist, with honest “not done” items.
- A “known limitations” list (for example, in-memory sessions would be lost on restart).
- Instructions to run the project without exposing any real secret.
Frequently Asked Questions
Are JWTs better than sessions?
Neither is universally better. Sessions give the server easy control, including instant revocation. JWTs suit APIs consumed by apps and services, but revocation needs extra design. For a first project with a website, sessions are usually simpler and safer.
Can I store passwords encrypted instead of hashed?
No. Encryption is reversible, so anyone who gets the key gets every password. Use a slow, salted one-way hash so the original is never recoverable by design.
Is SHA-256 good enough for passwords?
Not on its own. It is fast, which helps attackers test billions of guesses. Use Argon2, bcrypt or scrypt, which are intentionally expensive to compute.
Where should I keep an API key during development?
In an environment variable or a local .env file that is excluded from version control. If a key ever reaches a public repository, revoke and replace it immediately.
Do I need to build authentication from scratch to impress a mentor?
No. Understanding the flow matters more. Build the small version once to learn it, then use a maintained framework library for real projects and explain what it handles for you.
What is the difference between a 401 and a 403 response?
401 means the server could not establish who you are. 403 means it knows who you are but you are not permitted to perform the action. Using them correctly makes debugging much easier.
Will a two-week authentication project count for credit at RBU?
That depends on your programme’s rules, which the university’s public FAQ does not spell out for online internships. Ask your department in writing using the verification steps above, and do not assume credit unless you receive it in writing.
How do I show this work to employers?
Publish a clean repository with a README covering your design choices, the comparison table, the checklist and known limitations. Attach the internship completion certificate if you earn it, and be ready to explain every security decision in an interview.
Related Python & Backend Engineering guides
- Charutar Vidya Mandal University Students: Teamwork Rules for Your First Backend Sprint
- Mandsaur University Students: Deploying a Python API for the First Time on a Free Tier
- Rani Rashmoni Green University Students: Common Failures in Short Backend Internships and How to Avoid Them
- All Python & Backend Engineering internship guides
Ready to put this into practice?
Join the free two-week CareerSwami online internship in Python & Backend Engineering. The internship, the offer letter and the completion certificate are free.














