Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added password capabilities #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions js/zerobin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ function decompress(data) {
* @return encrypted string data
*/
function zeroCipher(key, message) {
return sjcl.encrypt(key,compress(message));
if ($('input#password').val().length==0) {
return sjcl.encrypt(key,compress(message));
}
return sjcl.encrypt(key+sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash($("input#password").val())),compress(message));
}
/**
* Decrypt message with key, then decompress.
Expand All @@ -59,7 +62,12 @@ function zeroCipher(key, message) {
* @return string readable message
*/
function zeroDecipher(key, data) {
return decompress(sjcl.decrypt(key,data));
try {
return decompress(sjcl.decrypt(key,data));
} catch(err){
var password = prompt("Please enter the password for this paste.","");
return decompress(sjcl.decrypt(key+sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(password)),data));
}
}

/**
Expand Down Expand Up @@ -278,7 +286,7 @@ function stateNewPaste() {
$('div#expiration').show();
$('div#remainingtime').hide();
$('div#language').hide(); // $('#language').show();
$('input#password').hide(); //$('#password').show();
$('#password').show();
$('div#opendisc').show();
$('button#newbutton').show();
$('div#pastelink').hide();
Expand Down
4 changes: 2 additions & 2 deletions tpl/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ <h3>{$VERSION}</h3>
<option value="python">Python</option>
</select>
</div>
<input id="password" value="Optional password..." style="display:none;" />
<input id="password" placeholder="Optional password..." style="display:none;" />
<div id="opendisc" class="button" style="display:none;">
<input type="checkbox" id="opendiscussion" name="opendiscussion" />
<label for="opendiscussion">Open discussion</label>
</div>
</div>
<div id="pastelink" style="display:none;"></div>
<div id="cleartext" style="display:none;"></div>
<div id="cleartext" class="prettyprint" style="display:none;"></div>
<textarea id="message" name="message" cols="80" rows="25" style="display:none;"></textarea>
<div id="discussion" style="display:none;">
<h4>Discussion</h4>
Expand Down