JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
hash and save auth credentials
authorJason Woofenden <jason@jasonwoof.com>
Thu, 6 Oct 2011 02:35:46 +0000 (22:35 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 6 Oct 2011 03:37:17 +0000 (23:37 -0400)
README [new file with mode: 0644]
auth.coffee [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..b22b84b
--- /dev/null
+++ b/README
@@ -0,0 +1,10 @@
+Setup
+=====
+
+1.     You'll need to save your auth credentials to ~/.libre.fm-cmus.auth:
+
+               unset HISTFILE
+               coffee -e "require('./auth.coffee').save_auth 'USERNAME','PASSWORD'"
+
+       (Substituting your libre.fm username and password of course.) The first
+       line disables history saving in bash, and perhaps other shells.
diff --git a/auth.coffee b/auth.coffee
new file mode 100644 (file)
index 0000000..619e169
--- /dev/null
@@ -0,0 +1,18 @@
+fs = require 'fs'
+crypto = require 'crypto'
+
+md5 = (str) ->
+       sum = crypto.createHash 'md5'
+       sum.update str
+       return sum.digest 'hex'
+
+new_auth_token = (user, pass) -> md5(user + md5(pass))
+
+save_auth = (user, pass, callback) ->
+       token = new_auth_token(user, pass)
+       text = JSON.stringify user: user, token: new_auth_token(user, pass)
+       fs.writeFile "#{process.env.HOME}/.libre.fm-cmus.auth", text, 'utf8', callback
+       return token
+
+exports.new_auth_token = new_auth_token
+exports.save_auth = save_auth