// Load modules

var Crypto = require('crypto');
var Hawk = require('hawk');
var Hapi = require('../lib');


// Declare internals

var internals = {
    salt: '' + Date.now()
};


internals.hashPassword = function (password) {

    var hash = Crypto.createHash('sha256');
    hash.update(password);
    hash.update(internals.salt);

    return hash.digest('base64');
};


internals.users = {
    john: {
        user: 'john'
    }
};


internals.passwords = {
    john: 'john'
};


internals.credentials = {
    'john': {
        id: 'john',
        key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
        algorithm: 'sha256'
    }
};


internals.loadUser = function (username, callback) {

    callback(null, internals.users[username], internals.hashPassword(internals.passwords[username]));
};


internals.getCredentials = function (id, callback) {

    callback(null, internals.credentials[id]);
};


internals.hawkHeader = function (id, path, server) {

    if (internals.credentials[id]) {
        return Hawk.getAuthorizationHeader('http://' + server.settings.host + ':' + server.settings.port + path, 'GET', { credentials: internals.credentials[id] });
    }
    else {
        return '';
    }
};

internals.handler = function (request) {

    request.reply('Success');
};


internals.main = function () {

    var config = {
        auth: {
            'default': {
                scheme: 'basic',
                loadUserFunc: internals.loadUser,
                hashPasswordFunc: internals.hashPassword
            },
            'hawk': {
                scheme: 'hawk',
                getCredentialsFunc: internals.getCredentials
            },
            'basic': {
                scheme: 'basic',
                loadUserFunc: internals.loadUser,
                hashPasswordFunc: internals.hashPassword
            }
        }
    };

    var http = new Hapi.Server(0, config);

    http.route([
        { method: 'GET', path: '/basic', config: { handler: internals.handler, auth: { strategies: ['basic'] } } },
        { method: 'GET', path: '/hawk', config: { handler: internals.handler, auth: { strategies: ['hawk'] } } },
        { method: 'GET', path: '/multiple', config: { handler: internals.handler, auth: { strategies: ['basic', 'hawk'] } } }
    ]);

    http.start(function () {

        console.log('\nBasic request to /basic:');
        console.log('curl ' + http.settings.uri + '/basic -H "Authorization: Basic ' + (new Buffer('john:john', 'utf8')).toString('base64') + '"');
        console.log('\nHawk request to /hawk:');
        console.log('curl ' + http.settings.uri + '/hawk -H \'Authorization: ' + internals.hawkHeader('john', '/hawk', http) + '\'');
        console.log('\nBasic request to /multiple:');
        console.log('curl ' + http.settings.uri + '/multiple -H "Authorization: Basic ' + (new Buffer('john:john', 'utf8')).toString('base64') + '"');
        console.log('\nHawk request to /multiple:');
        console.log('curl ' + http.settings.uri + '/multiple -H \'Authorization: ' + internals.hawkHeader('john', '/multiple', http) + '\'');
    });
};


internals.main();
@@ -464,20 +464,22 @@
  john: '
-john
+secret
 '%0A%7D;%0A%0A%0Ai
@@ -1018,25 +1018,16 @@
 awk.
-getAuthorizationH
+client.h
 eade
@@ -1148,16 +1148,22 @@
 s%5Bid%5D %7D)
+.field
 ;%0A    %7D%0A
@@ -1350,188 +1350,8 @@
 : %7B%0A
-            'default': %7B%0A                scheme: 'basic',%0A                loadUserFunc: internals.loadUser,%0A                hashPasswordFunc: internals.hashPassword%0A            %7D,%0A
     
@@ -2275,36 +2275,38 @@
 ew Buffer('john:
-john
+secret
 ', 'utf8')).toSt
@@ -2673,20 +2673,22 @@
 r('john:
-john
+secret
 ', 'utf8

Tweak auth example