简体   繁体   English

Postgres规则每60天会使用户密码无效

[英]Postgres Rule to invalidate user passwords every 60 days

I am having some trouble invalidating user passwords every 60 days on my postgres database: 我每60天就会在postgres数据库中使用户密码失效:

CREATE RULE user_expiration AS ON UPDATE TO users DO INSTEAD UPDATE user SET user_expires = user_expires + '60'

This will work every time the user changes their password, however it also works every time any update is issued on the records. 每次用户更改密码时,此功能都有效,但是,每次在记录上发布任何更新时,此功能也都有效。 How can I ensure that it only updates on the change password event? 如何确保它仅在更改密码事件时更新?

A trigger is a better solution. 触发器是一个更好的解决方案。 As of version 9.0 it has per column triggers , triggers that only fire when a certain column has been changed. 从9.0版开始,它具有每列触发器 ,仅当更改了特定列时才触发触发器。 In older versions you have to do the check inside the function, compare OLD.password and NEW.password before you deside to update the user_expires column. 在较旧的版本中,您必须在函数内部进行检查,然后比较OLD.password和NEW.password,然后再更新user_expires列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM