You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: module4-authentication-and-security/r1.1-defining-authentication-layer/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,7 +233,7 @@ Let's take the example above and add salting to it. When Alice is registering, s
233
233
234
234
The hashes for these two salted passwords will be entirely different, and when stored in the database, **we will need to store the salt too**. So that when they login we can retrieve it and prepend it to their supplied password. This way, the attacker will never know that they are using the same password when studying the hashes even if they know the salt. And their attack will take greater time adjusting for the introduction of salts. The same can be said for Jane, even though she is using a dictionary word, the hash will be for a different sequence of letters, and the hash table won't match it.
235
235
236
-
### **BCrypt**
236
+
### BCrypt
237
237
238
238
[BCrypt](https://en.wikipedia.org/wiki/Bcrypt) is a password hashing algorithm that is very hard to crack due to being super slow. It is adaptive and can be set up to be harder over time to provide more security by increasing the iteration count. It has an in-built feature to generate a salt when hashing so it won't need a salt column in the database.
Copy file name to clipboardExpand all lines: module4-authentication-and-security/r1.2-adding-authorization-layer/README.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ With authorization, we introduce another level of app security. In this lesson,
6
6
- Introduce role-based authorization
7
7
- How to restrict access to routes using authorization
8
8
9
-
## **Authorization**
9
+
## Authorization
10
10
11
11
- Authorization is a process by which a server determines if the client has permission to use a resource or access a file.
12
12
- Authorization is usually coupled with authentication so that the server has some concept of who the client is that is requesting access.
13
13
- The type of authentication required for authorization may vary; passwords may be required in some cases but not in others.
14
14
- In some cases, there is no authorization; any user may use a resource or access a file simply by asking for it. Most of the web pages on the Internet require no authentication or authorization.
15
15
16
-
## **Authentication**
16
+
## Authentication
17
17
18
18
- Authentication is used by a server when the server needs to know exactly who is accessing their information or site.
19
19
- Authentication is used by a client when the client needs to know that the server is the system it claims to be.
@@ -42,7 +42,7 @@ From these requirements, we can distinguish our app structure as follows:
42
42
- Endpoints like `/delete` would need an authorization guard. Which is a guard that contains the authentication guard, plus it also checks if the user is a `moderator`, before letting them complete the action. Otherwise, it shouldn't let them through.
43
43
- To elevate a user, an endpoint like `/elevate` would have the same authorization guard, but instead it will check if the user is an `admin`.
44
44
45
-
### **Implementation**
45
+
### Implementation
46
46
47
47
To implement this as simply as possible, we need to first define our roles as numbers. That is mainly to:
48
48
@@ -213,7 +213,7 @@ There is still a problem with our code though. It is very messy with lots of if-
213
213
214
214
In the next lesson, we will introduce an easier way to enforce our guards using a feature called **middleware**. We can define an `onlyAdmins`, `onlyModerators`, and `onlyAuthenticated` middleware that would stop unauthorized requests, and only let authorized access through.
215
215
216
-
## **Conclusion**
216
+
## Conclusion
217
217
218
218
In this lesson, we introduced authorization as a new security feature to our app. It would prevent users without the required access level from entering protected endpoints.
Copy file name to clipboardExpand all lines: module4-authentication-and-security/r1.2.1-authorization-through-middleware/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ This lesson objectives are:
9
9
- Implement authorization guard
10
10
- Guard certain endpoints with these middlewares
11
11
12
-
## **Middleware**
12
+
## Middleware
13
13
14
14
Middleware are functions that have access to the [request object](https://expressjs.com/en/4x/api.html#req) (`req`), the [response object](https://expressjs.com/en/4x/api.html#res) (`res`), and the next middleware function in the application’s request-response cycle. The next middleware function is commonly denoted by a variable named `next`.
15
15
@@ -195,6 +195,6 @@ Because we are using the `onlyAdmins` middleware, there is no need to check if t
195
195
196
196
> ⚠️ **Warning**: When you apply a middleware, you simply pass it as a **function**. Above we passed `onlyAdmins` without `()` parentheses. Middleware can be implemented using a configuration function as well, which is a function that takes configuration arguments and returns a middleware function. Read more about it in Express [documentation](https://expressjs.com/en/guide/writing-middleware.html#:~:text=Using%20Express%20middleware.-,Configurable%20middleware,-If%20you%20need).
197
197
198
-
## **Conclusion**
198
+
## Conclusion
199
199
200
200
In this lesson, we learned that everything in Express.js is basically a middleware that gets invoked somewhere. And by using middleware, we can structure our business logic in a clean approach. Middleware can be used for basically everything, and one of their use cases is to enforce authorization.
0 commit comments