Skip to content

Instantly share code, notes, and snippets.

/***************
Comes from a SO comment
@Josh K: This is a little over-the-top: $hash = sha1(sha1($password) ^ $salt);, $hash = sha1($password.$salt); would work just as well in practice (and faster). Also, the only reason I can think of to sha1(microtime()) is to constrain it to something that can fit in your column, and substr(str(microtime()), 0, 160) would work equally well (and faster), although I doubt microtime() gives a > 160 digit number anyway. Of course, you might be intentionally making it slow (so it would take more time to crack), but the performance should at least be mentioned.
Question: http://stackoverflow.com/questions/3038136/am-i-supposed-to-store-hashes-for-passwords/3038182#3038182
User: http://stackoverflow.com/users/212555/brendan-long
**************/
boolean excepted = false;
while(!excepted && (/* Condition */))
{
try
{
/* Amazing code */
}
catch(Exception e)
{
@joshkehn
joshkehn / gist:1127715
Created August 5, 2011 15:01
WebSocket - Part 3
var ws = new WebSocket("ws://localhost:40132");
ws.onopen = function()
{
output("Opened connection.");
};
ws.onmessage = function(e)
{
date = new Date(e.data);
if(isNaN(date.getHours()))
{
@joshkehn
joshkehn / gist:1127718
Created August 5, 2011 15:02
WebSocket - Part 4
function output(str)
{
document.getElementById("log").innerHTML = str;
}
@joshkehn
joshkehn / gist:1127720
Created August 5, 2011 15:02
WebSocket - Part 5
</script>
</head>
<body>
<div id="log"></div>
</body>
</html>
@joshkehn
joshkehn / gist:1127722
Created August 5, 2011 15:03
WebSocket - Part 6
var net = require("net"),
domains = ["*:*"];
@joshkehn
joshkehn / gist:1127725
Created August 5, 2011 15:05
WebSocket - Part 7
net.createServer(
function(socket)
{
/**
* Start the flash policy file
*/
socket.write("<?xml version=\"1.0\"?>");
socket.write("<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\n");
socket.write("<cross-domain-policy>\n");
@joshkehn
joshkehn / gist:1127726
Created August 5, 2011 15:06
WebSocket - Part 8
sudo node flashpolicy.js > flashpolicy.log & sleep 5; tail flashpolicy.log
@joshkehn
joshkehn / gist:1127728
Created August 5, 2011 15:06
WebSocket - Part 9
var sys = require("sys"),
ws = require('./lib/ws');
var server = ws.createServer();
intervals = {};
server.addListener("listening",
function()
{
sys.log("Listening for connections.");
@joshkehn
joshkehn / gist:1127730
Created August 5, 2011 15:08
WebSocket - Part 10
// Handle WebSocket Requests
server.addListener("connection",
function(conn)
{
conn.send("Connection: "+conn.id);
sys.log("Connection found: " + conn.id);