var md5= require('./md5');

/*
 * Hide the password. Uses the password to form authorization strings,
 * but provides no interface for exporting it.
 */
function user_credentials(username,password) {
  if (username.is_user_credentials &&
    typeof username.basic === 'function' &&
    typeof username.digest === 'function'
  ) {
    return username;
  }

  var basic_string= !password && password !== '' ?
    new Buffer(username, "ascii").toString("base64")
  :
    new Buffer(username+':'+password, "ascii").toString("base64")
  ;
  function basic()
  {
    return basic_string;
  }
  function digest(realm) {
    return !password && password !== '' ?
        md5(username+':'+realm)
        :
        md5(username+':'+realm+':'+password)
  }
  return {
    basic: basic,   // basic() returns a hash of username:password
    digest: digest, // digest(realm) returns a u & p hash for that realm
    username: username,
    is_user_credentials: true
  }
}

module.exports= user_credentials;

@@ -527,16 +527,17 @@
 4%22)%0A  ;%0A
+%0A
   functi
@@ -543,73 +543,183 @@
 ion 
-basic()%0A  %7B%0A    return basic_string;%0A  %7D%0A  function digest
+Credentials()%0A  %7B%0A    this.username= username;%0A  %7D%0A  Credentials.prototype.basic= function()%0A  %7B%0A    return basic_string;%0A  %7D%0A  Credentials.prototype.digest= function
 (realm)
+%0A 
  %7B%0A 
@@ -856,214 +856,113 @@
 %7D%0A  
+C
 re
-turn %7B%0A    basic: basic,   // basic() returns a hash of username:password%0A    digest: digest, // digest(realm) returns a u & p hash for that realm%0A    username: username,%0A    is_user_credentials: true%0A  %7D
+dentials.prototype.is_user_credentials= function()%0A  %7B%0A    return true;%0A  %7D%0A%0A  return new Credentials;
 %0A%7D%0A%0A

Refactor user credentials as a prototyped object.