import crypt
import sys

from django.core.exceptions import ObjectDoesNotExist
from django.utils.crypto import get_random_string

from . import models


class GoogleAppsPasswordValidator(object):
    """Update the Google Apps password when a user changes her password"""

    def password_changed(self, raw_password, user):
        # Hash the password in a way compatible with Google Apps: crypt with $6
        if sys.version_info >= (3,):
            password = crypt.crypt(raw_password, salt=crypt.METHOD_SHA512)
        else:
            password = crypt.crypt(raw_password.encode('utf-8'), '$6$' + get_random_string(16))
        try:
            user.gapps_password.password = password
        except ObjectDoesNotExist:
            models.GoogleAppsPassword.objects.create(user=user, password=password)
        else:
            user.gapps_password.save()

import crypt
import sys

from django.core.exceptions import ObjectDoesNotExist
from django.utils.crypto import get_random_string

from . import models


class GoogleAppsPasswordValidator(object):
    """Update the Google Apps password when a user changes her password"""

    def validate(self, password, user=None):
        return

    def password_changed(self, raw_password, user):
        # Hash the password in a way compatible with Google Apps: crypt with $6
        if sys.version_info >= (3,):
            password = crypt.crypt(raw_password, salt=crypt.METHOD_SHA512)
        else:
            password = crypt.crypt(raw_password.encode('utf-8'), '$6$' + get_random_string(16))
        try:
            user.gapps_password.password = password
        except ObjectDoesNotExist:
            models.GoogleAppsPassword.objects.create(user=user, password=password)
        else:
            user.gapps_password.save()

Add missing validate method to GoogleAppsPasswordValidator
Add missing validate method to GoogleAppsPasswordValidator

Django complains when updating the password:

    'GoogleAppsPasswordValidator' object has no attribute 'validate'

  import crypt
  import sys
  
  from django.core.exceptions import ObjectDoesNotExist
  from django.utils.crypto import get_random_string
  
  from . import models
  
  
  class GoogleAppsPasswordValidator(object):
      """Update the Google Apps password when a user changes her password"""
+ 
+     def validate(self, password, user=None):
+         return
  
      def password_changed(self, raw_password, user):
          # Hash the password in a way compatible with Google Apps: crypt with $6
          if sys.version_info >= (3,):
              password = crypt.crypt(raw_password, salt=crypt.METHOD_SHA512)
          else:
              password = crypt.crypt(raw_password.encode('utf-8'), '$6$' + get_random_string(16))
          try:
              user.gapps_password.password = password
          except ObjectDoesNotExist:
              models.GoogleAppsPassword.objects.create(user=user, password=password)
          else:
              user.gapps_password.save()
  
Add missing validate method to GoogleAppsPasswordValidator
## Code Before:
import crypt
import sys

from django.core.exceptions import ObjectDoesNotExist
from django.utils.crypto import get_random_string

from . import models


class GoogleAppsPasswordValidator(object):
    """Update the Google Apps password when a user changes her password"""

    def password_changed(self, raw_password, user):
        # Hash the password in a way compatible with Google Apps: crypt with $6
        if sys.version_info >= (3,):
            password = crypt.crypt(raw_password, salt=crypt.METHOD_SHA512)
        else:
            password = crypt.crypt(raw_password.encode('utf-8'), '$6$' + get_random_string(16))
        try:
            user.gapps_password.password = password
        except ObjectDoesNotExist:
            models.GoogleAppsPassword.objects.create(user=user, password=password)
        else:
            user.gapps_password.save()

## Instruction:
Add missing validate method to GoogleAppsPasswordValidator
## Code After:
import crypt
import sys

from django.core.exceptions import ObjectDoesNotExist
from django.utils.crypto import get_random_string

from . import models


class GoogleAppsPasswordValidator(object):
    """Update the Google Apps password when a user changes her password"""

    def validate(self, password, user=None):
        return

    def password_changed(self, raw_password, user):
        # Hash the password in a way compatible with Google Apps: crypt with $6
        if sys.version_info >= (3,):
            password = crypt.crypt(raw_password, salt=crypt.METHOD_SHA512)
        else:
            password = crypt.crypt(raw_password.encode('utf-8'), '$6$' + get_random_string(16))
        try:
            user.gapps_password.password = password
        except ObjectDoesNotExist:
            models.GoogleAppsPassword.objects.create(user=user, password=password)
        else:
            user.gapps_password.save()
