         new ImplementationError("no 'api.AuthImpl.findUser' and or
           'api.AuthImpl.jwtPayload' implementation.", 'signin_impl_error'))
 
-    _findUserPromise(login)
+    _hninvoke(api.AuthImpl, 'findUser', login)
     .then (user) ->
       Q.all [
         Q(user)

      _uuid = null
      if config.enableVerification and needVerify
        _uuid = uuid.v4()
      return _signUpPromise(userData, _uuid)
    .then (data) ->
      unless data.user
        throw new ImplementationError("no 'user' field in returned hash of

Auth = (api, next) ->
  config = api.config.auth

  # Used to call a function when it's unknown whether it uses node callback style
  # or returns a promise.
  # Mimics Q.ninvoke except that it will still work if the function is already using 
  # promises instead of node callback style
  # If object['name'] returns a promise, this simply forwards that promise on
  # If object['name'] resolves via node callback style, a promise is created and 
  # resolved when the callback is called
  _hninvoke = (object, name) ->
    deferred = Q.defer()
    callback = (err, result) ->
      if (err)
        deferred.reject(err)
      else
        deferred.resolve(result)
    args = [].slice.call(arguments, 2) || []
    args.push(callback)
    
    result = object[name].apply(object, args);

    if Q.isPromiseAlike(result)
      return result
    else
      return deferred.promise;

  _encodePassword =
    scrypt: (password) ->
      Q.ninvoke(scrypt, 'passwordHash', password, config.scrypt.maxtime)

  encodePassword = (password, callback) ->
    if api.AuthImpl and api.AuthImpl.encodePassword
      promise = _hninvoke(api.AuthImpl, 'encodePassword', password)
    else
      promise = _hninvoke(_encodePassword, 'scrypt', password)
    promise.nodeify(callback)
    promise

  _matchPassword =
    scrypt: (passwordHash, password) ->
