Преглед на файлове

Only output sha1 at the end - now this works

Dennis Rodewyk преди 5 години
родител
ревизия
c0b829165e
променени са 2 файла, в които са добавени 5 реда и са изтрити 6 реда
  1. 1 1
      hugo-encrypt.go
  2. 4 5
      shortcodes/hugo-encrypt.html

+ 1 - 1
hugo-encrypt.go

@@ -60,7 +60,7 @@ func encryptPage(path string) {
 		fmt.Printf("\nSHA1: % x\n", sha1.Sum(data))
 		sha1_sum := sha1.Sum(data)
 		sha1_string := hex.EncodeToString(sha1_sum[:])
-		finalcontent := (blockhtml + "\n<div id='verifyText'>" + sha1_string + "</div>")
+		finalcontent := (blockhtml + "\n<div id='sha1sum'>" + sha1_string + "</div>")
 		enchtml := encrypt(password, finalcontent)
 		block.RemoveAttr("data-password")
 		block.SetHtml(enchtml)

+ 4 - 5
shortcodes/hugo-encrypt.html

@@ -22,7 +22,7 @@
 	{{ else }}
 		{{- $passphrase -}}
 	{{ end }}
-	<p>{{ i18n "protectedbypwd" }} The password is <code>{{ $.Scratch.Get "passphrase" }}</code>.</p>
+	<p>{{ i18n "protectedbypwd" }}</p>
 
 	<div class='hugo-encrypt-form'>
 		<input
@@ -129,16 +129,15 @@
 					/**
 					* calculate sha1 of decrypted text and check if it
 					* matches the sha1 at the bottom of the decrypted text
-					* to get the hash that was added during encryption we
+					* to get the same hash that was added during encryption we
 					* need to remove the last line
 					*/
-					var hash = CryptoJS.SHA1(res.replace(/[\w\W]+?\n+?/,"").replace(/\r?\n?[^\r\n]*$/, ""));
+					var hash = CryptoJS.SHA1(res.replace(/\r?\n?[^\r\n]*$/, ""));
 					var result = CryptoJS.enc.Hex.stringify(hash);
 					if ( res.includes(result) ) {
 						cipher.parentElement.outerHTML = interpreteMarkdown(res);
 						userStorage.setItem(storageKey, password);
-						document.getElementById("beginProtectedContent").innerHTML = "Beginning of decrypted content";
-						document.getElementById("endProtectedContent").innerHTML = "End of decrypted content";
+						document.getElementById("sha1sum").innerHTML = "sha1: " + result;
 					} else {
 						if (type === "input") {
 							alert('{{ i18n "wrongpwd" }}');