diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index e37f45df8d..8a90bc1eb6 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -783,10 +783,11 @@ class BoincToken { return $db->lookup('token', 'BoincToken', $clause); } - static function lookup_valid_token($userid, $token) { + static function lookup_valid_token($userid, $token, $type) { $db = BoincDb::get(); $token = BoincDb::escape_string($token); - return self::lookup("userid=$userid and token='$token' and expire_time > unix_timestamp()"); + $type = BoincDb::escape_string($type); + return self::lookup("userid=$userid and token='$token' and expire_time > unix_timestamp() and type = '$type'"); } static function enum($where_clause) { diff --git a/html/inc/email.inc b/html/inc/email.inc index a66425bdcf..f99a36397b 100644 --- a/html/inc/email.inc +++ b/html/inc/email.inc @@ -20,6 +20,7 @@ // Don't put specific message text here. require_once("../inc/util.inc"); +require_once("../inc/token.inc"); require_once("../project/project.inc"); // send an email, using PHPMailer or not. @@ -109,6 +110,27 @@ function is_valid_email_addr($addr) { return (bool) $match; } +function send_confirm_delete_email($user) { + $token = create_confirm_delete_account_token($user); + if ( $token == null ) { + error_page("Error creating token. Please try again later."); + } + + $subject = "Confirm your request to delete your account at ".PROJECT; + $body = "This email was sent in response to a request on the ".PROJECT." web site. + +You have requested to delete your account at ".PROJECT.". In order to do this, use the following link to confirm your intent to delete your account. ". +"The link will take you to a web page where you will be asked to enter your password and complete the process of deleting your account. + +".secure_url_base()."delete_account_confirm.php?id=$user->id&token=$token + +This link is valid for 1 day. + +For further information and assistance with ".PROJECT.", visit ".secure_url_base(); + + return send_email($user, $subject, $body); +} + function salted_key($key) { return md5($key.'oogabooga'); } diff --git a/html/inc/token.inc b/html/inc/token.inc new file mode 100644 index 0000000000..1dd52f1b84 --- /dev/null +++ b/html/inc/token.inc @@ -0,0 +1,50 @@ +. + +// express a time difference in readable form, e.g. "7 days ago". +// If it's more than 30 days, just show the date +// + +require_once("../inc/boinc_db.inc"); +require_once("../inc/util.inc"); + +// Constants for valid token types +define("TOKEN_TYPE_DELETE_ACCOUNT", "D"); + +// Constants for token durations +define("TOKEN_DURATION_ONE_DAY", "86400"); + +function create_confirm_delete_account_token($user) { + $token = random_string(); + $ret = BoincToken::insert("(token,userid,type,expire_time) values ('$token', $user->id, '".TOKEN_TYPE_DELETE_ACCOUNT."', unix_timestamp()+".TOKEN_DURATION_ONE_DAY.")"); + if ( !$ret ) { + return null; + } + return $token; +} + +function is_valid_delete_account_token($user, $token) { + $boincToken = BoincToken::lookup_valid_token($user->id, $token, TOKEN_TYPE_DELETE_ACCOUNT); + if ( $boincToken == null ) { + return false; + } + return true; +} + + +?> \ No newline at end of file diff --git a/html/inc/user_util.inc b/html/inc/user_util.inc index b28198de16..3a63576320 100644 --- a/html/inc/user_util.inc +++ b/html/inc/user_util.inc @@ -30,6 +30,23 @@ function do_passwd_rehash($user, $passwd_hash) { $result = $user->update(" passwd_hash='$database_passwd_hash' "); } +function check_passwd($user, $passwd) { + $passwd_hash = md5($passwd.$user->email_addr); + + if ( password_verify($passwd_hash, $user->passwd_hash) ) { + return true; + } + + if ($passwd_hash == $user->passwd_hash) { + // if password is the legacy md5 hash, then rehash to update to + // a more secure hash + do_passwd_rehash($user, $passwd_hash); + return true; + } + + return false; +} + function is_banned_email_addr($email_addr) { global $banned_email_domains; if (isset($banned_email_domains)) { diff --git a/html/ops/test_token.php b/html/ops/test_token.php index a9bb123754..d88685ea81 100755 --- a/html/ops/test_token.php +++ b/html/ops/test_token.php @@ -24,5 +24,16 @@ echo $boincToken->type . "\n"; echo $boincToken->create_time . "\n"; echo $boincToken->expire_time . "\n"; +echo "---------------\n"; +$boincToken = BoincToken::lookup_valid_token(0, $token, 'T'); +if ( $boincToken != null ) { + echo "Found valid token\n"; +} + +echo "---------------\n"; +$boincToken = BoincToken::lookup_valid_token(0, 'notrealtoken', 'T'); +if ( $boincToken == null ) { + echo "Successfully didn't find invalid token\n"; +} ?> diff --git a/html/user/delete_account_request.php b/html/user/delete_account_request.php index 64b10dc2d6..cdbcb09265 100644 --- a/html/user/delete_account_request.php +++ b/html/user/delete_account_request.php @@ -24,11 +24,11 @@ $user = get_logged_in_user(); $config = get_config(); if ( !parse_bool($config, "enable_delete_account") ) { error_page( - tra("These feature is disabled. Please contact the project administrator.") + tra("This feature is disabled. Please contact the project administrator.") ); } -page_head(tra("Remove Account")); +page_head(tra("Delete Account")); echo "
".tra("You have the ability to delete your account. Please note that this cannot be undone once it is completed.")."
" ."".tra("The process works as follows:")."
" diff --git a/html/user/delete_account_request_action.php b/html/user/delete_account_request_action.php index e69de29bb2..6d79c28ebd 100644 --- a/html/user/delete_account_request_action.php +++ b/html/user/delete_account_request_action.php @@ -0,0 +1,54 @@ +. + +require_once("../inc/util.inc"); +require_once("../inc/account.inc"); +require_once("../inc/user_util.inc"); +require_once("../inc/email.inc"); +require_once("../inc/password_compat/password.inc"); + +$user = get_logged_in_user(); + +$config = get_config(); +if ( !parse_bool($config, "enable_delete_account") ) { + error_page( + tra("This feature is disabled. Please contact the project administrator.") + ); +} + +//Verify password +$user = get_logged_in_user(); +$passwd = post_str("passwd"); + +if( !check_passwd($user, $passwd) ) { + sleep(LOGIN_FAIL_SLEEP_SEC); + page_head("Password incorrect"); + echo "The password you entered is incorrect. Please go back and try again.\n"; + page_tail(); + exit; +} + +send_confirm_delete_email($user); + + +page_head(tra("Confirmation Email Sent")); + +echo "".tra("The email to confirm your request to delete your account has been sent.")."
"; + +page_tail(); +?> \ No newline at end of file