Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 531443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:18:06+00:00 2026-05-13T09:18:06+00:00

I am writing a password-reset page for my website. Here’s my idea: a. User

  • 0

I am writing a password-reset page for my website. Here’s my idea:

a. User click the “forgot password” link on the login page

b. Redirect to my password-reset page

c. User enter his email address

d. A email message sent to the email address with the link to reset his/her password. The link has security code like ?code=”xxxx” in it.

e. User open the link and enter new password, and then click the submit button.

f. My page change user’s password.

My question is for step f. In step e, when user opened the link, I could verify his security code and then show the ‘new password’ and the ‘confirm password’ fields to user. But when the user clicked the submit button, how could I know this is a real request submited by the user instead of a hacker? Maybe I am wrong, but I think hacker can easily simulate such field data, since there is no validation fields.

There are some idea I can think of to validate the request in step f, but I don’t know whether they are right.
1. Add a encrypted cookie in step e and check it in step f?
2. Use a session variable in step e and check it in step f?
3. Add a hidden field in step e and check it in step f?

Are those approaches ok? Which one is better, or is there any better one?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:18:06+00:00Added an answer on May 13, 2026 at 9:18 am

    A user entering their username and reset code should log them into the site just as their username and password would. The difference is you then immediately force them to change their password. With this password reset method you’re implicitly trusting that the user is the owner of the email account where the code was sent.

    Edit:

    Ok, so I don’t know the first thing about ASP.net.

    However, I’ve handled this problem many times before. Here is a solution of mine in PHP:

    <?php
    class AuthController extends Zend_Controller_Action
    {
        public function identifyAction()
        {
            if ($this->_request->isPost()) {
                $username = $this->_getParam('username');
                $password = $this->_getParam('password');
    
                if (empty($username) || empty($password)) {
                    $this->_flashError('Username or password cannot be blank.');
                } else {
                    $user = new User();
                    $result = $user->login($username, $password);
    
                    if ($result->isValid()) {
                        $user->fromArray((array) $this->_auth->getIdentity());
    
                        if ($this->_getParam('changepass') || $user->is_password_expired) {
                            $this->_redirect('auth/change-password');
                            return;
                        }
                        $this->_doRedirect($user);
                        return;
                    } else {
                        $this->_doFailure($result->getIdentity());
                    }
                }
            }
            $this->_redirect('/');
        }
    
        public function forgotPasswordAction()
        {
            if ($this->_request->isPost()) {
                // Pseudo-random uppercase 6 digit hex value
                $resetCode = strtoupper(substr(sha1(uniqid(rand(),true)),0,6));
    
                Doctrine_Query::create()
                    ->update('dUser u')
                    ->set('u.reset_code', '?', array($resetCode))
                    ->where('u.username = ?', array($this->_getParam('username')))
                    ->execute();
    
                $mail = new Zend_Mail();
                $mail->setBodyText($this->_resetEmailBody($this->_getParam('username'), $resetCode));
                $mail->setFrom('no-reply@example.com', 'Example');
                $mail->addTo($this->_getParam('username'));
                $mail->setSubject('Forgotten Password Request');
                $mail->send();
    
    
                $this->_flashNotice("Password reset request received.");
                $this->_flashNotice("An email with further instructions, including your <em>Reset Code</em>, has been sent to {$this->_getParam('username')}.");
                $this->_redirect("auth/reset-password/username/{$this->_getParam('username')}");
            }
        }
    
        public function resetPasswordAction()
        {
            $this->view->username = $this->_getParam('username');
            $this->view->reset_code = $this->_getParam('reset_code');
    
            if ($this->_request->isPost()) {
                $formData = $this->_request->getParams();
                if (empty($formData['username']) || empty($formData['reset_code'])) {
                    $this->_flashError('Username or reset code cannot be blank.');
                    $this->_redirect('auth/reset-password');
                } elseif ($formData['new_password'] !== $formData['confirm_password']) {
                    $this->_flashError('Password and confirmation do not match.');
                    $this->_redirect('auth/reset-password');
                } else {
                    $user = new User();
                    $result = $user->loginWithResetCode($formData['username'], $formData['reset_code']);
    
                    if ($result->isValid()) {
                        $user->updatePassword($result->getIdentity(), $formData['new_password']);
    
                        $user->fromArray((array) $this->_auth->getIdentity());
                        $this->_setLegacySessionData($user);
    
                        $this->_flashNotice('Password updated successfully!');
                        $this->_doRedirect($user);
                    } else {
                        $this->_doFailure($result->getIdentity());
                        $this->_redirect('auth/reset-password');
                    }
                }
            }
        }
    
        protected function _doFailure($username)
        {
            $user = Query::create()
                ->from('User u')
                ->select('u.is_locked')
                ->where('u.username = ?', array($username))
                ->fetchOne();
    
            if ($user->is_locked) {
                $lockedMessage = Config::get('auth.lock_message');
                if (!$lockedMessage) {
                    $lockedMessage = 'This account has been locked.';
                }
                $this->_flashError($lockedMessage);
            } else {
                $this->_flashError('Invalid username or password');
            }
        }
    }
    

    If you can follow this, it should give you a good idea of what to do. I’ll try to summarize:

    identifyAction

    This is the regular “login” using username and password. It logs the user in and stores their identity in the session.

    forgotPasswordAction

    This presents the user with a form requesting their username. After entering their username a reset code is generated, stored in their entry in the user table, and they are emailed as well as redirected to the reset password page. This page is unauthenticated, the user is not logged in.

    resetPasswordAction

    This is where the user is presented with the “resetPassword” form. They must provide their username and the reset code they received via email. This authenticates the user with the given username and reset code, just as if the reset code were a password. If the credentials are valid the user is then redirected to the changePassword action where they are permitted to change their password. The changePasswordAction (not shown) requires the user be authenticated (logged in) either via username/password or username/resetCode

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a password reset page. Logic: User requests pw It's sent to their
I am writing an app to save password with a login interface. The user
I am writing a JSF page, where user can change his password. I based
I'm writing a 'reset password' facility for a website and as part of it
i'm thinking about writing a WPF program that would require login and password at
I'm writing a simple password-recovery function for the website I'm developing and I was
I'm writing a password verify directive : Directives.directive(passwordVerify,function(){ return { require:ngModel, link: function(scope,element,attrs,ctrl){ ctrl.$parsers.unshift(function(viewValue){
I'm writing a script in PHP to allow a user to change their password.
Here is my issue, I'm creating a website with a little login and resetting
I'm writing a self service password reset system in c#, .Net 3.5 - one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.