
Laravel Mein Authentication Aur Authorization Ka Farq: A Complete Guide in Hindi
🔐 Authentication Kya Hai?
Authentication ka matlab hota hai user ki identity verify karna. Jab koi user login karta hai, toh system yeh check karta hai ki uske dwara diya gaya email aur password valid hai ya nahi.
Laravel mein authentication kaafi aasan hai. Laravel built-in Auth
system ke through session-based authentication provide karta hai.
✅ Example: User Authentication in Laravel
Agar credentials sahi hain, Laravel ek session create karta hai jise future requests ke liye use kiya jata hai.
✅ Authorization Kya Hai?
Authorization ka matlab hai ye decide karna ki ek authenticated user ko kin cheezon ka access hai. Yani ek baar user login ho gaya, tab system check karega ki user kya-kya actions perform kar sakta hai.
Laravel mein authorization implement karne ke liye do major tools hote hain:
-
Policies – Specific model actions ke liye.
-
Gates – General purpose logic ke liye.
✅ Example: Policy Use Karna
✅ Example: Gate Define Karna
📊 Authentication vs Authorization (Table Format)
Feature | Authentication | Authorization |
---|---|---|
Matlab | User ki identity verify karna | User ke actions/resources ko allow karna |
Kab Use Hota? | Login ke time | Login ke baad, action perform karte waqt |
Laravel Tools | Auth, Middleware, Session | Policies, Gates |
Example | Auth::attempt([...]) | Gate::define(...) , Policy@method |
🎯 Conclusion
Laravel mein authentication aur authorization alag-alag responsibilities nibhaate hain:
-
Authentication: Kya user valid hai?
-
Authorization: Kya user ko access dena chahiye?
In dono ka clear distinction aapke Laravel application ko secure, organized, aur role-based banata hai.
Agar aap Laravel developer hain ya seekh rahe hain, toh in concepts ko samajhna aapko production-level applications banane mein madad karega.
🙌 Happy Coding, Amigos!
Agar aapko yeh blog useful laga ho toh share karna na bhoolen. Laravel se related aur topics ke liye niche comment karein ya follow karein.
🔎 Bonus Tip:
Laravel 10+ mein aap Laravel Breeze, Jetstream, ya Fortify jaise starter kits ka use karke authentication aur authorization ko aur bhi aasani se setup kar sakte hain.
Need Help? Comment below ya poochhiye Laravel ke kisi bhi topic par – hum hain yahan aapke liye!
Comments
Be the first to comment!
Leave a Comment