     when 'email'
       method = tryOneEmail
     when 'account'
-      method = tryOneEither
+      method = tryOneAccount
     when 'token'
       method = tryOneToken
     else

  m = addr.match matchEmail
  m isnt null

tryOneToken = (ddp, options, cb) ->
  ddp.call 'login', [{ resume: process.env[options.env] }], (err, res) ->
    return cb err, res?.token

attemptLogin = (ddp, user, pass, options, cb) ->
  hash = crypto.createHash 'sha256'
  hash.update pass, 'utf8'
  digest = { digest: hash.digest('hex'), algorithm: 'sha-256' }
  ddp.call 'login', [{user: user, password: digest}], (err, res) ->
    unless err and err.error is 400 and options.plaintext
      if err

  # ddp.on 'message', (msg) ->
  #   console.error("ddp message: " + msg)

login.loginWithToken = loginWithToken
login.loginWithUsername = loginWithUsername
login.loginWithEmail = loginWithEmail
login.loginWithAccount = loginWithAccount

module?.exports = login
