   !passwordFormMessages.getErrorMessage field
 
 validatePassword = (newPassword, messageField) ->
-  return unless passwordReadyForValidation
+  return unless newPasswordReadyForValidation
   try
     User.validatePassword newPassword, messageField
     passwordFormMessages.resetMessages messageField

    return # Make sure CoffeeScript does not return anything

  'blur input#new-password': (event, template) ->
    passwordReadyForValidation = passwordFieldModified
    newPassword = $('#new-password').val()
    validatePassword newPassword, "new-password"

    return # Make sure CoffeeScript does not return anything

  'keyup, paste input#new-password': (event, template) ->
    passwordFieldModified = true
    newPassword = $('#new-password').val()
    validatePassword newPassword, "new-password"

    return # Make sure CoffeeScript does not return anything


usernameFormMessages = new FormMessages()
usernameReadyForValidation = false
usernameFieldModified = false

passwordFormMessages = new FormMessages()
newPasswordReadyForValidation = false
newPasswordFieldModified = false

resetUsernameForm = ->
  usernameFormMessages.resetMessages()
  usernameReadyForValidation = false
  usernameFieldModified = false

resetPasswordForm = ->
  passwordFormMessages.resetMessages()
  $('#current-password').val('')
  $('#new-password').val('')
  newPasswordReadyForValidation = false
  newPasswordFieldModified = false

# Reset forms when settings page becomes active
Deps.autorun ->
