# "Not Recently Used" password policy not working

**URL:** <https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030>\
**Category:** Configuring the server\
**Tags:** admin-console, user-federation, ldap\
**Created:** [October 20, 2022, 1:23pm UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030 "2022-10-20T13:23:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcb](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dcb](https://forum.keycloak.org/u/dcb)\
**Post date:** [October 20, 2022, 1:23pm UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/1 "2022-10-20T13:23:26Z")

</div>

Hi,

I’m trying to use keycloak to recover user passwords (Forgot password) but the Password Policy is not working as expected.

I’m using [Quay](http://quay.io/keycloak/keycloak:18.0) image and ldap Active Directory User Federation with “Import Users” and “Validate Password Policy” enabled.

On the Authentication Password Policy keycloak is validating as expected all the policies (e.g. minimum length, not username, special characters) except the “Not Recently Used” policy.

The “Not Recently Used” policy is configured with a value of 3, but the user may repeat the same password any times he wants.

This policy does not work for users imported from ldap? I’m doing it the wrong way? Or this is a bug?

Thanks!

---

<div class="post-metadata">

**Author:** ![dcb](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dcb](https://forum.keycloak.org/u/dcb)\
**Post date:** [December 12, 2022, 1:02pm UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/2 "2022-12-12T13:02:02Z")

</div>

Hi, could anyone help? Any help/suggestions are welcome!

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [December 12, 2022, 7:51pm UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/3 "2022-12-12T19:51:25Z")

</div>

When using LDAP user federation, Keycloak does not know about the recent used passwords and password policies are not used at all, because the policies configured in Keycloak might possibly clash with policies in LDAP. With LDAP user federation, only the password policies living in the LDAP will be taken into account, but by the LDAP itself, not by Keycloak.

---

<div class="post-metadata">

**Author:** ![dcb](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dcb](https://forum.keycloak.org/u/dcb)\
**Post date:** [December 12, 2022, 9:30pm UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/4 "2022-12-12T21:30:38Z")

</div>

Thanks @dasniko! I was thinking maybe keycloak could get some feedback from LDAP about these policies.

---

<div class="post-metadata">

**Author:** ![Nitu](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Nitu](https://forum.keycloak.org/u/Nitu)\
**Post date:** [May 23, 2023, 5:18am UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/5 "2023-05-23T05:18:23Z")

</div>

Hi,  
Thanks for your response to the issue. I am also facing same problem. Is it possible to modify something in HistoryPasswordPolicyProvider ?If yes…what ??

Also if these policies do not work in keycloak for ldap user federation, then first we need to validate password in ldap and then hit keycloak for token ? Am i right. ?

regards

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [May 23, 2023, 7:35am UTC](https://forum.keycloak.org/t/not-recently-used-password-policy-not-working/18030/6 "2023-05-23T07:35:33Z")

</div>

In the meantime the feature was introduced, that you can configure in LDAP user federation settings that also the Keycloak password policies should be evaluated. But I doubt that this will work with the most recent _n_ passwords, as Keycloak doesn’t know about the passwords used in LDAP. IMHO only semantic password policies will work properly.
