Changeset 696234
- Timestamp:
- 04/11/2013 08:09:20 PM (13 years ago)
- Location:
- expirepassword/trunk
- Files:
-
- 4 edited
-
classes/public.expirepassword.php (modified) (2 diffs)
-
expirepassword.php (modified) (1 diff)
-
includes/functions.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
expirepassword/trunk/classes/public.expirepassword.php
r695551 r696234 92 92 // 3. Check the key is valid - *before* accessing user data 93 93 // Get the stored key 94 $thekey = shrkey_get_usermeta_ oncer( $user->ID, '_shrkey_password_expired_key' );94 $thekey = shrkey_get_usermeta_timed_oncer( $user->ID, '_shrkey_password_expired_key' ); 95 95 // Get and parse the passed key 96 96 $passedkey = preg_replace('/[^a-z0-9]/i', '', $_POST['key']); … … 154 154 } 155 155 156 // We are going to save our key to a oncer for later checking 157 shrkey_set_usermeta_ oncer( $user->ID, '_shrkey_password_expired_key', $oncerkey);156 // We are going to save our key to a oncer for later checking - but set it to expire in 5 minutes 157 shrkey_set_usermeta_timed_oncer( $user->ID, '_shrkey_password_expired_key', $oncerkey, '+5 minutes' ); 158 158 159 159 login_header( __('Expired Password', 'expirepassword'), '<p class="message reset-pass">' . __('Your password has <strong>expired</strong>. Enter a new password below.', 'expirepassword') . '</p>', $errors ); -
expirepassword/trunk/expirepassword.php
r695551 r696234 2 2 /* 3 3 Plugin Name: Expire Password 4 Version: 1. 04 Version: 1.1 5 5 Plugin URI: https://github.com/shrkey/expirepassword 6 6 Description: Forces a user to change their password at their netx login, can be set to force a password change for a new user on first sign in -
expirepassword/trunk/includes/functions.php
r695551 r696234 1 1 <?php 2 /* 3 * Oncer functions - a oncer is a piece of data that is deleted from the database as soon as it is retrieved 4 */ 2 5 3 6 if( !function_exists( 'shrkey_has_usermeta_oncer') ) { … … 44 47 } 45 48 49 /* 50 * Timed Oncers - a timed oncer is a oncer that only exists until a set time, and then it is removed 51 */ 52 53 if( !function_exists( 'shrkey_has_usermeta_timed_oncer') ) { 54 function shrkey_has_usermeta_timed_oncer( $user_id, $meta ) { 55 56 $value = get_user_meta( $user_id, $meta, true ); 57 if(!empty($value)) { 58 return true; 59 } else { 60 return false; 61 } 62 63 } 64 } 65 66 if( !function_exists( 'shrkey_get_usermeta_timed_oncer') ) { 67 function shrkey_get_usermeta_timed_oncer( $user_id, $meta ) { 68 69 $value = get_user_meta( $user_id, $meta, true ); 70 if(!empty($value)) { 71 // 1. remove it as we only want it readable once 72 delete_user_meta( $user_id, $meta ); 73 // 2. Split the oncer into it's parts 74 $storage = explode( '##', $value ); 75 // Array map the arrays to get rid of rogue spaces / characters 76 if( is_array( $storage) ) { 77 $storage = array_map( 'trim', $storage ); 78 } 79 // 3. Check it has the correct number of parts 80 if( count($storage) == 3 ) { 81 // 4. Rebuild the hash 82 $newhash = md5( 'SHRKEY' . $storage[0] . $storage[1] ); 83 // 5. Check the hash is correct and it hasn't expired 84 if( $newhash == $storage[2] && time() <= $storage[1] ) { 85 // 6. return it 86 return $storage[0]; 87 } else { 88 return ''; 89 } 90 } else { 91 return ''; 92 } 93 } 94 95 // Our catch all drop out return empty string return :) 96 return ''; 97 98 } 99 } 100 101 if( !function_exists( 'shrkey_set_usermeta_timed_oncer') ) { 102 function shrkey_set_usermeta_timed_oncer( $user_id, $meta, $value, $expires = '+1 day' ) { 103 104 $expirytime = strtotime( $expires ); 105 $storage = array( $value, 106 $expirytime, 107 md5( 'SHRKEY' . $value . $expirytime ) 108 ); 109 110 update_user_meta( $user_id, $meta, implode( '##', $storage ) ); 111 112 } 113 } 114 115 if( !function_exists( 'shrkey_delete_usermeta_timed_oncer') ) { 116 function shrkey_delete_usermeta_timed_oncer( $user_id, $meta ) { 117 118 delete_user_meta( $user_id, $meta ); 119 120 } 121 } 122 123 /* 124 * Options functions that get the information from the options or sitemeta table depending a setting 125 */ 126 46 127 if( !function_exists( 'shrkey_get_option') ) { 47 128 function shrkey_get_option($key, $default = false) { -
expirepassword/trunk/readme.txt
r695568 r696234 4 4 Requires at least: 3.0 5 5 Tested up to: 3.5.1 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 8 8 Enables a site administrator to expire a users password and enforce a change to a new, different password before they can login again
Note: See TracChangeset
for help on using the changeset viewer.