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 6844485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:23:03+00:00 2026-05-27T00:23:03+00:00

I create a function to edit user password here the function code. function updateUser

  • 0

I create a function to edit user password here the function code.

function updateUser ()
{


    $current = md5($_POST['cpassword']);
    $new = md5($_POST['npassword']);
    $newc = md5($_POST['npasswordc']);

    $name = $_POST['username'];
    connectDB();

        $check = mysql_query("SELECT password FROM user WHERE user_name = '$name'") 

        or die(mysql_error());


            if ($check != $current) {

            ?> <div id="error">
                <?php die('Current password is wrong. Press back to try again.'); ?>
                </div> <?php

            }

        if ($new == $newc) :

            $sql = "UPDATE user SET password = '$new' WHERE user_name = '$name'";
            execute($sql);

            ?> <div id="error">
            <?php die('Password Successfully Updated. Back to <a href="/dashboard">dashboard</a>');
            ?> </div>  <?php

        else :  ?> <div id="error">
            <?php die('New Password did not match. Press back to try again');
            ?> </div>  <?php

        endif;


}

the value will be pass by the form on different page, everything seem to work fine. When I try to change password, it say successful, and when I check in the database, the md5 value is changing that mean the password was change.

But when I try to change password of same username, I still need to enter the old password for current password, even though in database it already changed?

What seem to be the problem?

Thank you

  • 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-27T00:23:04+00:00Added an answer on May 27, 2026 at 12:23 am

    $check is a mysql resource, not a value. You might do

    if($check && (mysql_num_rows($check) > 0))
    {
      $res = mysql_fetch_assoc($check);
      if($res['password'] != $current) {
    

    Be careful of SQL injections, you should do at least

    $name = mysql_real_escape_string($_POST['username']);
    

    before entering it into the query.

    Also, md5 is a week hashing algorithm, I strongly suggest you use a SALT, and better hash algos like at the very least sha1() or better go for the sha2 family (sha256, sha512, for ex) or bcrypt

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

Sidebar

Related Questions

I'm using CreateWindowEx() function to create an EDIT window, i.e. where a user can
I can create function pointers in Fortran 90, with code like real, external ::
I am new to Prolog and I'm trying to to create function that will
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
This string: CREATE USER %s PASSWORD %s, (user, pw) always gets expanded to: CREATE
Here's my user-defined table type... CREATE TYPE [dbo].[FooType] AS TABLE( [Bar] [INT], ) This
I decided to drop md5() as the password-encrypting algorithm when storing user passwords in
How do I create a 'user defined function' that returns a 'cursor' back to
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function: CREATE FUNCTION [dbo].[ListStockBySubCategory] ( @CategoryID varchar(10), @SubCategoryID varchar(10), @startRowIndex

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.