miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /  
 

Switching from MD5 to SH1 passwords

 
Author tom322
Active Member
#1 | Posted: 24 May 2019 07:08 
So I've been wondering about proper steps to convert md5 function to sha1. I think the following should be all steps, unless I miss something? : )

1. In database, in the _users table, change the following fields: 'user_password' | 'user_newpwdkey' | 'user_newpasswd' from 32 to 40 characters (sha1 takes 40).

2. In bb_cookie.php file, change the current writeUserPwd to this:

if($action=='editprefs' and isset($_POST['passwd2'])) $hash=sha1; else $hash=md5;

function writeUserPwd($pwd){
return $hash($pwd);
}
3. Look up and change this condition in files: admin_fileXXX.php, bb_cookie.php, and bb_func_login.php

from:

if(strlen($admin_pwd)==32)
to:

if(strlen($admin_pwd)==40)
4. Force password change via this code added to bb_plugins.php (keep this code for some time, a month or so):

if($user_id>1) {
$md5Cookie=substr(substr($_COOKIE[$cookiename],strlen($user_usr)),1,-11); // clear md5 encoded cookie
if(strlen($md5Cookie)==32) {

echo '<script>alert('Please change your password now!');</script>';
header("{$rheader}{$main_url}/{$indexphp}action=prefs");
exit;
}
}
5. Change admin password in setup_options.php to something strong.

Is it good, did it cover all scenarios? :

Author Paul
Lead Developer 
#2 | Posted: 24 May 2019 14:32 
At first, I suppose you know that following PHP guide,

It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See the Password Hashing FAQ for details and best practices.
SHA1 stands not far away from MD5 in this case :)

Anyway, the proper solution below (I've tested on my local environment):

1. Change the length of the user_password field in the $Tu table (minibbtable_users by default) - here you are right:

alter table minibbtable_users modify user_password varchar(40) not null default '';
2. bb_cookie.php - change default function to this (for an existing forum):

function writeUserPwd($pwd){
if(isset($_POST['mode']) and $_POST['mode']=='login' and strlen($GLOBALS['userpassword'])==32) {
$method='md5';
}
else $method='sha1';
return call_user_func($method, $pwd);
}
For a new forum, it's enough just to have:

function writeUserPwd($pwd){
return sha1($pwd);
}
3. On an existing forum, force your users to change/update passwords if they are still in MD5 (don't apply this for a new forum) - we could not change MD5 to SH1 straight, so it's really required that all of your users change or update the passwords manually:

/* Changing to SH1 */
if($user_id>1){
$cookie=explode('|', $_COOKIE[$cookiename]);

if(strlen($cookie[1])==32 and $action!='prefs' and $action!='editprefs') {
header("{$rheader}{$main_url}/{$indexphp}action=prefs");
exit;
}

if($action=='prefs' and strlen($cookie[1])==32){
$warning='<span class="warning">Because of security updates, we require to change or update your password now. If you wouldn\'t like to change the password, just repeat the older password below.</span>';
}

}
/* --Changing to SH1 */
4. OPTIONAL - if you are on a secured hosting and do not mind to keep the Admin's password in a clear form, change nothing. If you'd like to keep the Admin's password encoded in SHA1, do as mentioned in p.#3 of tom322's post above.

These steps could be useful also if you change to another encoding algorithm - except it would be much more difficult to plug it into existing forum, if the final encoding result is not equal to some defined length. For a new forum, another algorithm is more easier to plug-in at the initial forum running stage.

P.S. Always avoid any JavaScript "solutions", as more as possible :)

Author tom322
Active Member
#3 | Posted: 25 May 2019 18:53 
Thank you - from my tests it worked. BUT I was wondering about adding some random value to user-specified password so that in DB is never stored exact user password.

Currently there is this function:

function writeUserPwd($pwd){
return md5($pwd);
}
What if we replaced it to something like:

function writeUserPwd($pwd){
$pwd=str_ireplace(array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','u','p','r','w','v','z','q'),array('v','m','G','o','q','a','Y','b','v','s','i','C','r','j','U','f','7','4'),$pwd);
return md5($pwd);
}
Then the password stored in DB / cookie would never be the same as user entered it; in case of DB breach or a stolen cookie, attacker would only get this one-time password that is valid for forum and not valid for other things associated with this user's email (some people use the same password for different sites).

Author tom322
Active Member
#4 | Posted: 25 May 2019 20:21 
.. and if my suggestion above makes sense, what would be the best way of checking if current member changed password (I mean without changing md5 to sha1, so without comparing the lenght of the string) - I guess the only way would be to set a cookie in the action like:

if($user_id>1 and !isset($_COOKIE['passwordChanged']))
{
if(isset($_POST['passwd2']) and strlen($_POST['passwd2'])>5 and $_POST['passwd']==$_POST['passwd2']) {
setcookie('passwordChanged','1',0,$cookiepath,$cookiedomain,1,1);
}
else
{
header("{$rheader}{$main_url}/{$indexphp}action=prefs");
$warning.='<br>Please update your password for better security!';
}
}

?

Author Paul
Lead Developer 
#5 | Posted: 25 May 2019 21:08 
DB actually doesn't store an exact password. Hashed value is compared to the same way encoded value user enters in the login form. DB stores an encoded version of it. There is a way to encode MD5 only if it's kind of a regular simple value, which is already available in a kind of known values database. If it's a difficult-to-guess password, it would take time to decode if it ever possible.

Your solution with replacing is not truly acceptable, I guess. MD5 is exactly about generating a unique hash for a value, but if you replace or change something, I doubt you could achieve that it will be unique, and some different values may have the same encoding value in result. It would make it even less secure. It's better not to touch a default function that way, and actually you won't achieve anything more secure with it.

I wouldn't rely on cookies in terms of some strong checking as well. What if this cookie is not set or deleted - you lose any chance to check for something.

Author tom322
Active Member
#6 | Posted: 25 May 2019 22:48 
Yes, even though my point was that since MD5 hash can be reversed into a real password, then adding these replacements would make sure that DB / cookie only stores a truly random password.

In other words, for security it would be best NOT to allow users to enter their own password but generate a random password for them, so I thought that adding this replacement function to the writeUserPwd function would achieve that because user-entered password would be randomized.

Author tom322
Active Member
#7 | Posted: 25 May 2019 22:54 
Besides, the replacements could actually add truly unique characters that users are unlikely to use but would make them stronger, like !@@#$%^&*()_+ etc.. I think it's a good idea:

Author Paul
Lead Developer 
#8 | Posted: 26 May 2019 10:37 
It's a good idea to suggest users strong passwords, which they enter in forms, but it's absolutely not about changing an encoded value somehow. You won't achieve anything when making an intrusion into default encoding algorithm.

Author TrevorNoah
Partaker
#9 | Posted: 14 Jun 2019 08:34 
MD5 is the best around, right?
Today I was sitting in on a CS Capstone presentation (Final presentation before graduating, etc). One of my peers' presentation was today and I thought I'd check it out.

The person mentions that they salted and encrypted the stored user credentials within the database. At the end of the presentation, someone asked:

You mentioned that you store your user credentials by encrypting and salting them, so which algorithm did you use and how did you randomize the salt on each?

Their response:

I ended up researching algorithms a lot and decided to use MD5 because it's the most secure algorithm I've found. It also has a salt built in so I didn't have to worry about that.

Author Paul
Lead Developer 
#10 | Posted: 14 Jun 2019 18:46 
TrevorNoah:
I ended up researching algorithms a lot and decided to use MD5 because it's the most secure algorithm I've found
If this is a quote, I'd be curious to know its author's credentials :)

Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /
 Switching from MD5 to SH1 passwords
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Get the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑