Skip to content

Commit 3a91c35

Browse files
committed
updated pass post
1 parent abe90f8 commit 3a91c35

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

assets/img/postpass.mp4

416 KB
Binary file not shown.

content/posts/adding_password_protection_to_a_hugo_post.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ This method lacks complete security. Anyone with basic Hugo knowledge can access
1616
This post do not talk about
1717

1818
{{< admonition type=success title="What this post cover" open=false >}}
19-
1. Easy method to assign a password to any Hugo post.
19+
1. Easy method to assign a password to any Hugo post (not 100% secured)
2020
2. Users will be prompted to enter a password to access the post.
2121
3. Unique password for each post
2222
{{< /admonition >}}
2323

24-
25-
26-
2724
Before we proceed, open the post [Top Secret](http://localhost:1313/posts/top_secret/) that is protection with a password. When prompted, enter the password `1234` to read the top secret.
2825

29-
## Add a new parameter, `password`
26+
![password-protection](https://pouch.jumpshare.com/preview/GA_t8X7rJkwOSdsolhK4H7ND9kHBOgRq7g98Vcr_R62DovJUg6TLF0gQt5140AoHfJD7SLqCLZnupx2aUWWIM4A9dVtAxDj6JHloBdAvI18)
27+
28+
----
29+
## 1. Add a new parameter, `password`
3030
To give you a sense of what I mean by "Add a new parameter" take a look at the `password` parameter at the line [#9](https://github.com/lazydeveloper/lazydeveloper.github.io/blob/1477fa46fe7425899d15470398e4405f6c0cfb0a/content/posts/top_secret.md?plain=1#L8) in the code below.
3131
```
3232
---
@@ -42,11 +42,12 @@ password: "1234"
4242
```
4343
Any value you input for the password parameter here (for example, 1234) will act as the password for accessing this post. So, include this new parameter in an existing or new post, as we'll proceed to implement the password protection logic in the following step.
4444

45-
## Implementing logic for the password parameter
45+
----
46+
## 2. Implementing logic for the password parameter
4647

4748
It's time to write the logic, Let's add a script to the default post layout. In my case its [single.html](https://github.com/lazydeveloper/lazydeveloper.github.io/blob/main/themes/LoveIt/layouts/posts/single.html) located at `themes/LoveIt/layouts/posts/`. The path or the file name may be different in your setup.
4849

49-
### Add the following code snippets to your layout file (single.html).
50+
**Add the following code snippets to your layout file (single.html).**
5051

5152
01. Add this div at the starting of the article class. This will ensures that the content is hidden initially if a password is set.
5253
```
@@ -71,19 +72,16 @@ It's time to write the logic, Let's add a script to the default post layout. In
7172
};
7273
</script>
7374
```
74-
75-
76-
7775
Here my [single.html](https://github.com/lazydeveloper/lazydeveloper.github.io/blob/1477fa46fe7425899d15470398e4405f6c0cfb0a/themes/LoveIt/layouts/posts/single.html) file for quick reference. Look at the line#[21](https://github.com/lazydeveloper/lazydeveloper.github.io/blob/1477fa46fe7425899d15470398e4405f6c0cfb0a/themes/LoveIt/layouts/posts/single.html#L22) and line#[104 to 118](https://github.com/lazydeveloper/lazydeveloper.github.io/blob/1477fa46fe7425899d15470398e4405f6c0cfb0a/themes/LoveIt/layouts/posts/single.html#L104)
7876
7977
80-
81-
## Testing the protection
78+
----
79+
## 3. Testing the protection
8280
Now that you know how to add a password parameter and the logic to check the password, you can create a new post with a password parameter or add the password parameter to an existing post. This method should work fine.
8381
8482
However, as previously discussed, this method is not 100% secure. At the time of writing this post, I'm not certain about replacing the password with a GitHub variable or secret, or using any similar mechanism to hide the password. If I manage to achieve this (fingers crossed), I will update this post accordingly.
8583
86-
Please share your opinions or any other suggestions by [commenting here](https://github.com/lazydeveloper/lazydeveloper.github.io/discussions/new/
84+
Please share your opinions or any other suggestions by [commenting here](https://github.com/lazydeveloper/lazydeveloper.github.io/discussions/new/)
8785
8886
8987

public/sitemap.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
33
xmlns:xhtml="http://www.w3.org/1999/xhtml"
44
><url>
5-
<loc>https://shiva.dev/posts/adding_password_protection_to_a_hugo_post/</loc><lastmod>2024-07-07T13:55:20-05:00</lastmod></url><url>
6-
<loc>https://shiva.dev/categories/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
7-
<loc>https://shiva.dev/categories/development/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
8-
<loc>https://shiva.dev/tags/hugo/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
9-
<loc>https://shiva.dev/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
10-
<loc>https://shiva.dev/tags/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
11-
<loc>https://shiva.dev/posts/top_secret/</loc><lastmod>2024-07-08T16:30:39-04:00</lastmod></url><url>
5+
<loc>https://shiva.dev/posts/adding_password_protection_to_a_hugo_post/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
6+
<loc>https://shiva.dev/categories/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
7+
<loc>https://shiva.dev/categories/development/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
8+
<loc>https://shiva.dev/tags/hugo/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
9+
<loc>https://shiva.dev/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
10+
<loc>https://shiva.dev/tags/</loc><lastmod>2024-07-09T01:52:13-04:00</lastmod></url><url>
11+
<loc>https://shiva.dev/posts/top_secret/</loc><lastmod>2024-07-09T01:38:52-04:00</lastmod></url><url>
1212
<loc>https://shiva.dev/posts/lunr_search_for_hugo/</loc><lastmod>2024-06-23T13:12:21-04:00</lastmod></url><url>
1313
<loc>https://shiva.dev/tags/lunr/</loc><lastmod>2024-06-23T13:12:21-04:00</lastmod></url><url>
1414
<loc>https://shiva.dev/tags/search/</loc><lastmod>2024-06-23T13:12:21-04:00</lastmod></url><url>

0 commit comments

Comments
 (0)