'Authenticates with the pin.'

def pin_auth(self, request):

    exhausted = False
    auth = False
    trust = self.check_pin_trust(request.environ)
    bad_cookie = False
    if (trust is None):
        self._fail_pin_auth()
        bad_cookie = True
    elif trust:
        auth = True
    elif (self._failed_pin_auth > 10):
        exhausted = True
    else:
        entered_pin = request.args.get('pin')
        if (entered_pin.strip().replace('-', '') == self.pin.replace('-', '')):
            self._failed_pin_auth = 0
            auth = True
        else:
            self._fail_pin_auth()
    rv = Response(json.dumps({'auth': auth, 'exhausted': exhausted}), mimetype='application/json')
    if auth:
        rv.set_cookie(self.pin_cookie_name, ('%s|%s' % (int(time.time()), hash_pin(self.pin))), httponly=True)
    elif bad_cookie:
        rv.delete_cookie(self.pin_cookie_name)
    return rv
