Passwords >> Gallery 2

ragedigital

Joined: 2007-03-07
Posts: 5
Posted: Wed, 2007-03-07 02:49

I need to know how to generate the password used by Gallery2 for transfer from my current database to G2.

Passwords are not crypted - yet.

Thanks,

darrin

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32155
Posted: Wed, 2007-03-07 15:02

i suggest you use g2's api:
- to create users:
from modules/core/AdminCreateUser.inc

list ($ret, $user) =
		    GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryUser');
		if ($ret) {
		    return array($ret, null);
		}

		if (!isset($user)) {
		    return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT),
				 null);
		}

		$ret = $user->create($form['userName']);
		if ($ret) {
		    if (!($ret->getErrorCode() & ERROR_COLLISION)) {
			return array($ret, null);
		    }

		    /* Set our error status and fall back to the view */
		    $error[] = 'form[error][userName][exists]';
		} else {
		    $user->setEmail($form['email']);
		    $user->setFullName($form['fullName']);
		    $user->setLanguage($form['language']);
		    GalleryUtilities::unsanitizeInputValues($form['password1'], false);
		    $user->changePassword($form['password1']);

		    $ret = $user->save();
		    if ($ret) {
			return array($ret, null);
		    }

- to change passwords:

		    $user->changePassword($form['password1']);

		    $ret = $user->save();
		    if ($ret) {
			return array($ret, null);
		    }

- to learn more about the password hash algorithm:
modules/core/classes/GalleryUser.class function changePassword()

--------------
Doumentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

Login or register to post comments
ragedigital

Joined: 2007-03-07
Posts: 5
Posted: Wed, 2007-03-07 15:17

Is there not a simpler way to convert a string like "bill" into a usable password for Gallery2?

For phpbb I simply converted using MD5(), but gallery2 is a modified version of it.

If I reset their password through the Admin page of Gallery2,
then I can recreate a useable one with the following code:

Quote:
$password = 'bill;
$salt = "";

if (empty($salt)) {
for ($i = 0; $i < 4; $i++) {
$char = mt_rand(48, 109);
$char += ($char > 90) ? 13 : ($char > 57) ? 7 : 0;
$salt .= chr($char);
}
}

else {
$salt = substr($salt, 0, 4);
}

$guess = $salt . md5($salt . $password);

I've already loaded all the other information, but this seems to be the hang up.

Thanks for you help!

Login or register to post comments
valiant

Joined: 2003-01-04
Posts: 32155
Posted: Wed, 2007-03-07 15:22

i guess that's a copy from GalleryUtilities, right?

to create the hashes password, use:
1.
require_once('modules/core/classes/GalleryUtilities.class');
print GalleryUtilities::md5Salt($password);

2. set g2_User.g_hashedPassword (database) to the resulting value.

3. clear the db cache:
FAQ: How can I clear cached data?

Login or register to post comments
ragedigital

Joined: 2007-03-07
Posts: 5
Posted: Wed, 2007-03-07 15:35

Yes, I copied that from GalleryUtilities.

That is great help - thanks so much!

Login or register to post comments
ragedigital

Joined: 2007-03-07
Posts: 5
Posted: Wed, 2007-03-07 16:15

Worked perfect - Thanks!

Login or register to post comments
XulaYmAn

Joined: 2008-03-18
Posts: 1
Posted: Tue, 2008-03-18 09:38

Hi,
Well i tried to create a password with the function you gave, it creates the password and the database is updated as well but it does not allow me to log in:S. The strange thing is that it allows me to log in with the default admin/admin username/password, whereas no such user with that password exists in the database. Any idea? Any help would be highly appreciated. Thank you.

Regards

Login or register to post comments
beckett
beckett's picture

Joined: 2002-08-16
Posts: 3469
Posted: Tue, 2008-03-25 03:39

Did you clear the db cache after updating the database?

-Beckett

--

(gratuitous link to my gallery! ~~ http://photos.beckettmw.com/ )

Login or register to post comments