docs: def check_password(reference, attempt):
      """
      Compare a reference password with the user attempt.
  
      >>> check_password('{PLAIN}foo', 'foo')
      True
      >>> check_password(u'{PLAIN}bar', 'bar')
      True
      >>> check_password(u'{UNKNOWN}baz', 'baz')
      False
      >>> check_password(u'no-encoding', u'no-encoding')
      False
      >>> check_password(u'{SSHA}q/uVU8r15k/9QhRi92CWUwMJu2DM6TUSpp25', u're-foo')
      True
      >>> check_password(u'{BCRYPT}$2b$12$NfKivgz7njR3/rWZ56EsDe7..PPum.fcmFLbdkbP.chtMTcS1s01C', 'foo')
      True
      """
      if reference.startswith(u'{PLAIN}'):
          if reference[7:] == attempt:
              return True
      elif reference.startswith(u'{SSHA}'):
          # In python3 b64decode takes inputtype as bytes as opposed to str in python 2, and returns
          # binascii.Error as opposed to TypeError
          if six.PY3:  # pragma: no cover
              try:
                  if isinstance(reference, six.text_type):
                      ref = b64decode(reference[6:].encode('utf-8'))
                  else:
                      ref = b64decode(reference[6:])
              except binascii.Error:
                  return False  # Not Base64
          else:  # pragma: no cover
              try:
                  ref = b64decode(reference[6:])
              except TypeError:
                  return False  # Not Base64
          if isinstance(attempt, six.text_type):
              attempt = attempt.encode('utf-8')
          salt = ref[20:]
          b64_encoded = b64encode(hashlib.sha1(attempt + salt).digest() + salt)
          if six.PY3:  # pragma: no cover
              # type(b64_encoded) is bytes and can't be compared with type(reference) which is str
              compare = six.text_type('{SSHA}%s' % b64_encoded.decode('utf-8') if type(b64_encoded) is bytes else b64_encoded)
          else:  # pragma: no cover
              compare = six.text_type('{SSHA}%s' % b64_encoded)
          return compare == reference
      elif reference.startswith(u'{BCRYPT}'):
          # bcrypt.hashpw() accepts either a unicode encoded string or the basic string (python 2)
          if isinstance(attempt, six.text_type) or isinstance(reference, six.text_type):
              attempt = attempt.encode('utf-8')
              reference = reference.encode('utf-8')
          if six.PY3:  # pragma: no cover
              return bcrypt.hashpw(attempt, reference[8:]) == reference[8:]
          else:  # pragma: no cover
              return bcrypt.hashpw(
                  attempt.encode('utf-8') if isinstance(attempt, six.text_type) else attempt,
                  str(reference[8:])) == reference[8:]
      return False