From 7352fd23a8160e9013019655874c5a37bcf64896 Mon Sep 17 00:00:00 2001 From: shumit taher Date: Tue, 30 Sep 2025 05:07:04 +0000 Subject: [PATCH] :sparkles: added pin hash compatibility. --- docs/configuring.md | 2 +- src/components/LinkItems/Section.vue | 7 +++++-- src/utils/ConfigSchema.json | 2 +- src/utils/SectionHelpers.js | 7 ++++++- user-data/conf.yml | 4 ++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/configuring.md b/docs/configuring.md index e75ac2d1..99027420 100644 --- a/docs/configuring.md +++ b/docs/configuring.md @@ -243,7 +243,7 @@ For more info, see the **[Authentication Docs](/docs/authentication.md)** **`items`** | `array` | _Optional_ | An array of items to be displayed within the section. See [`item`](#sectionitem). Sections must include either 1 or more items, or 1 or more widgets. **`widgets`** | `array` | _Optional_ | An array of widgets to be displayed within the section. See [`widget`](#sectionwidget-optional) **`displayData`** | `object` | _Optional_ | Meta-data to optionally override display settings for a given section. See [`displayData`](#sectiondisplaydata-optional) -**`pin`** | `string` | _Optional_ | The PIN code for unlocking this section if `secret` under `displayData` is true. Provide at the section root (e.g., pin: 2749). Validated client-side and remembered only for the current browser tab/session. Not intended for protecting highly sensitive data. Only for Child-proofing. if not entered but section is locked then default pin will be 0000 +**`pin`** | `string` | _Optional_ | The PIN code for unlocking this section if `secret` under `displayData` is true. Provide at the section root (e.g., pin: 2749). Validated client-side and remembered only for the current browser tab/session. Not intended for protecting highly sensitive data. Only for Child-proofing. if not entered but section is locked then default pin will be 0000. optionally user can input SHA256 hash of their pin here. **[⬆️ Back to Top](#configuring)** diff --git a/src/components/LinkItems/Section.vue b/src/components/LinkItems/Section.vue index 9e9271fb..742ed1c1 100644 --- a/src/components/LinkItems/Section.vue +++ b/src/components/LinkItems/Section.vue @@ -126,6 +126,7 @@ import ContextMenu from '@/components/LinkItems/SectionContextMenu.vue'; import PinInput from '@/components/InteractiveEditor/PinInput.vue'; import ErrorHandler from '@/utils/ErrorHandler'; import StoreKeys from '@/utils/StoreMutations'; +import { pinHash } from '@/utils/SectionHelpers'; import { sortOrder as defaultSortOrder, localStorageKeys, @@ -141,7 +142,7 @@ export default { groupId: String, title: String, icon: String, - pin: String, + pin: [String, Number], displayData: Object, items: Array, widgets: Array, @@ -337,7 +338,9 @@ export default { sessionStorage.setItem(SECRET_UNLOCKED_KEY, JSON.stringify(map)); const unlockPins = JSON.parse(sessionStorage.getItem(SECRET_UNLOCKED_KEY) || '{}'); const sectionKey = this.sectionRef; - if (unlockPins[sectionKey] === this.pin) { + const savedPin = unlockPins[sectionKey]; + + if (savedPin === pinHash(pin) || savedPin === pin.toString()) { this.pinError = ''; this.isUnlocked = true; } else { diff --git a/src/utils/ConfigSchema.json b/src/utils/ConfigSchema.json index f65d25c4..0c3b4fc4 100644 --- a/src/utils/ConfigSchema.json +++ b/src/utils/ConfigSchema.json @@ -758,7 +758,7 @@ }, "pin":{ "title": "Section Pin", - "type": "string", + "type": ["number", "string"], "description": "PIN to unlock this section" }, "displayData": { diff --git a/src/utils/SectionHelpers.js b/src/utils/SectionHelpers.js index dfad7e67..3d4cf350 100644 --- a/src/utils/SectionHelpers.js +++ b/src/utils/SectionHelpers.js @@ -1,5 +1,5 @@ /* Helper functions for Sections and Items */ - +import sha256 from 'crypto-js/sha256'; import { hideFurnitureOn } from '@/utils/defaults'; /* Returns false if page furniture should be hidden on said route */ @@ -39,3 +39,8 @@ export const applyItemId = (inputSections) => { }); return sections; }; + +export const pinHash = (pin) => { + if (!pin) return null; + return sha256(pin).toString().toUpperCase(); +}; diff --git a/user-data/conf.yml b/user-data/conf.yml index 32a0e161..058e7501 100644 --- a/user-data/conf.yml +++ b/user-data/conf.yml @@ -46,7 +46,7 @@ sections: icon: far fa-hands-helping - name: Stuff icon: fas fa-rocket - pin: "1112" + pin: FE91A760983D401D9B679FB092B689488D1F46D92F3AF5E9E93363326F3E8AA4 displayData: secret: true items: @@ -62,7 +62,7 @@ sections: target: newtab - name: Stuff 2 icon: fas fa-rocket - pin: "1114" + pin: 1114 displayData: secret: true items: