开发者

Require new password on first login to Wordpress

开发者 https://www.devze.com 2022-12-19 12:10 出处:网络
I am trying to set up a Wordpress site that requires users to login.The usernames are going to be pre-populated into the db, with 1 default password for all.Once they enter the default password, they

I am trying to set up a Wordpress site that requires users to login. The usernames are going to be pre-populated into the db, with 1 default password for all. Once they enter the default password, they need to be taken to another login screen that will act as a registration page for them. They cannot change their username, but are required to ch开发者_StackOverflow社区ange their password. I cannot find any plugins that accomplish this (if someone knows of a pre-existing plugin, that would be great!). Anyone have any suggestions on how to accomplish this or point me in the right direction on where someone has accomplished this already? Thanks J


This is how I would do it. Setup your login form to accept username and password. If password is equal to the default password, set an arbitrary value in the usermeta table. On your login landing page have the logic check for that usermeta value, if exists, display the form for creating a new password. Upon successful password change, remove the usermeta value.

Here's some stuff to get you started...

var $creds = array();
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;

if ($creds['user_password']=='default'){
$metakey = 'mustchangepw';
$metavalue = 'true';
update_usermeta( $userid, $metakey, $metavalue ); 
}

$user = wp_signon( $creds, false );


Once they login just advise them to change their password via their profile page in wp-admin. Once a user is created they can change their display name but not their user name by defualt. You can use the adminimise http://wordpress.org/extend/plugins/adminimize/ to hide certain features. I'm not sure if there is an 'easy' way to achieve it.

Also if someone realizes that there is a default password, they might try to to access another account if the user names are in a predictable format, such as 'FirsnameLastname'. Might be worth using a simple password generator and apply unique default passwords.

0

精彩评论

暂无评论...
验证码 换一张
取 消