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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:09:24+00:00 2026-06-02T05:09:24+00:00

I am working with the moodle system, but it turns out that it uses

  • 0

I am working with the moodle system, but it turns out that it uses md5 salt hashing. I found some come, so maybe you could explaint it to me because I am have only basic knowledge of php.

function validate_internal_user_password($user, $password) {
global $CFG;

if (!isset($CFG->passwordsaltmain)) {
    $CFG->passwordsaltmain = '';
}

$validated = false;

if ($user->password === 'not cached') {
    // internal password is not used at all, it can not validate

} else if ($user->password === md5($password.$CFG->passwordsaltmain)
        or $user->password === md5($password)
        or $user->password === md5(addslashes($password).$CFG->passwordsaltmain)
        or $user->password === md5(addslashes($password))) {
    // note: we are intentionally using the addslashes() here because we
    //       need to accept old password hashes of passwords with magic quotes
    $validated = true;

} else {
    for ($i=1; $i<=20; $i++) { //20 alternative salts should be enough, right?
        $alt = 'passwordsaltalt'.$i;
        if (!empty($CFG->$alt)) {
            if ($user->password === md5($password.$CFG->$alt) or $user->password === md5(addslashes($password).$CFG->$alt)) {
                $validated = true;
                break;
            }
        }
    }
}

if ($validated) {
    // force update of password hash using latest main password salt and encoding if needed
    update_internal_user_password($user, $password);
}

return $validated;

}

Would it be hard to change it that after entering simple text it would became hashed?

  • 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-06-02T05:09:25+00:00Added an answer on June 2, 2026 at 5:09 am

    This is a password validation with some legacy password in them.

    There are 5 forms of passwords it will allow:

    • md5(password)
    • md5(addslashes(password))
    • md5(password + generic salt)
    • md5(addslashed) + generic salt)
    • md5(password + saltX)

    First things first, what is md5? md5 is “message digest 5”. Long story short it’s a function to transforms a string into a 32 character string call a hash. The main property of the hash is that it’s hard (as in computationally hard) to get the original string back. Ideal for storing passwords, right? 🙂

    But a password alone is not enough. Imagine your password is “dragon” (very bad password btw). If you happen to know that “dragon” is “8621ffdbc5698829397d97767ac13db3” in md5 you can know the password just by looking at the hash. So you add what is called a ‘salt’. Which is just another word to add to the password before hashing.

    If your salt is “notsob1gs3cret” the password is essentially “dragonnotsob1gs3cret” which results in: “c47948e6b966357f1b9a3732c4ee7c72” which doesn’t look anything like “8621ffdbc5698829397d97767ac13db3”. This is another property of a hash, input that is similar should produce output that is not at all similar, enough to be almost as similar as any random word.

    If your attacker has never seen the salt “notsob1gs3cret” it wont be so easy for him to guess the original password.

    So about your code. Disregard the addslashes, that is probably from some legacy bug. It looks like someone tried to add a salting mechanism later on and still wanted all the old password to work, but it looks a bit clumsy. Ideally you’d only have one valid password mechanism and upgrade your weaker security.

    There are 20 different salts, which is a fair idea I suppose .. but the code doesn’t seem to know which one was used .. so it tries all of them? That’s weird and could potentially be unsafe.

    To hash a bit of text just do:

    $text = "a bit of text";
    var_dump(md5($text));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on Moodle but have a php-mysql related doubt which is turning
I'm a student working on a module for moodle cms (course management system) of
When working with some open source projects (in my case Joomla and Moodle), I've
I am working with Moodle 2.2.1 but have a basic php-mysql problem. I am
I am working on Moodle 2.2.1 and have created dynamic.csv files using certain queries.
Working on a bunch of forms at the moment and I'm finding that I
Working on a website that has Employee and Branch entities, using a database table
Working on a movie website and would love to find an API that I
I'm working on a new Moodle Assignment plugin. How can I include a custom
Working on an extension that use the new experimental devtools apis. How do you

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.