JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
hash and save auth credentials
[libre-fm-client-daemon.git] / auth.coffee
1 fs = require 'fs'
2 crypto = require 'crypto'
3
4 md5 = (str) ->
5         sum = crypto.createHash 'md5'
6         sum.update str
7         return sum.digest 'hex'
8
9 new_auth_token = (user, pass) -> md5(user + md5(pass))
10
11 save_auth = (user, pass, callback) ->
12         token = new_auth_token(user, pass)
13         text = JSON.stringify user: user, token: new_auth_token(user, pass)
14         fs.writeFile "#{process.env.HOME}/.libre.fm-cmus.auth", text, 'utf8', callback
15         return token
16
17 exports.new_auth_token = new_auth_token
18 exports.save_auth = save_auth