moh-hasher 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -2
- package/package.json +1 -1
package/index.js
CHANGED
@@ -36,9 +36,22 @@ export function hash(secret) {
|
|
36
36
|
// Unhasher (decode)
|
37
37
|
export function unhash(encodedSecret) {
|
38
38
|
let decoded = '';
|
39
|
+
let temp = ''; // Temporary storage for matching encoded sequence
|
39
40
|
for (let i = 0; i < encodedSecret.length; i++) {
|
40
|
-
|
41
|
-
|
41
|
+
temp += encodedSecret[i];
|
42
|
+
// Check if the temp sequence exists in the decodeMap
|
43
|
+
if (decodeMap[temp]) {
|
44
|
+
decoded += decodeMap[temp];
|
45
|
+
temp = ''; // Reset temp once a valid match is found
|
46
|
+
}
|
47
|
+
}
|
48
|
+
// If there's any leftover temp data that couldn't be decoded, append it
|
49
|
+
if (temp) {
|
50
|
+
decoded += temp;
|
42
51
|
}
|
43
52
|
return decoded;
|
44
53
|
}
|
54
|
+
|
55
|
+
export function compare(original, hashed) {
|
56
|
+
return hash(original) === hashed;
|
57
|
+
}
|