Obtaining the users PW?

ddum

Joined: 2005-08-08
Posts: 37
Posted: Sun, 2010-08-29 12:35

Hello!

(Running a pretty current csv of G2 on Ubuntu 10.4)

I am aparently missing the "Heureka-moment" when it comes to using the core classes.

I am looking to code a simple web-form that will execute a few functions if the user/pass combo is that of an existing gallery user.
Basically, a form with a user/pass that will see if the password matches said user name of Gallery.

I have found GalleryCoreApi.class, GalleryUtilities.Class and GalleryUser.class, but I cannot find any example on how I would do this.
I guess I am missing in particular the connection on how to fetch the hashed PW given a certain user name. Sure, I could write my own code for this... but why, when there is such a nice toolbox in place already :)

Any pointer?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-08-29 15:21

GalleryCoreApi.class
fetchUserByUserName

GalleryUser.class
getHashedPassword
isCorrectPassword

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-08-29 15:45

example usage:

list($ret, $user) = GalleryCoreApi::fetchUserByUserName('plain_text_username');
if ($ret) {
    print "Error fetching user:".$ret->getAsHtml();
    exit;
}
if($user->isCorrectPassword('plain_text_password')){
    echo "hurray";
}else{
    echo "wrong";
}

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
ddum

Joined: 2005-08-08
Posts: 37
Posted: Sun, 2010-08-29 22:11

Thanks... But now quite right aparently(?)

Fatal error: Call to a member function search() on a non-object in /var/www/clients/client1/web13/web/gallery2/modules/core/classes/helpers/GalleryUserHelper_medium.class on line 137

<?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', '1' );
require_once '/var/www/gallerimaster.skyddsrummet.net/web/gallery2/modules/core/classes/GalleryCoreApi.class';
require_once '/var/www/gallerimaster.skyddsrummet.net/web/gallery2/modules/core/classes/GalleryUtilities.class';
require_once '/var/www/gallerimaster.skyddsrummet.net/web/gallery2/modules/core/classes/GalleryUser.class';

list($ret, $user) = GalleryCoreApi::fetchUserByUserName('janjoh');
if ($ret) {
print "Error fetching user:".$ret->getAsHtml();
exit;
}
if($user->isCorrectPassword('atestpassword')){
echo "hurray";
}else{
echo "wrong";
}

?>

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-08-29 23:52
<?php
/* Connect to gallery */
function init() {
    require_once ('/full/system/path/to/gallery2/embed.php');
    $ret = GalleryEmbed::init(array());
    if ($ret) {
        print 'GalleryEmbed::init failed, here is the error message: '.$ret->getAsHtml();
        exit;
    }
    GalleryEmbed::done();
}

/* Check user password by username */
function checkuser($username, $password) {
    global $gallery;
    list($ret, $user) = GalleryCoreApi::fetchUserByUserName($username);
    if ($ret) {
        print "Error fetching user:".$ret->getAsHtml();
        exit;
    }
    if($user->isCorrectPassword($password)){
        return "hurray";
    }else{
        return "wrong";
    }
}

init();
echo checkUser('plain_text_username', 'plain_text_password');
?>

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
ddum

Joined: 2005-08-08
Posts: 37
Posted: Mon, 2010-08-30 00:03

AHA!

There was the Heureka-moment!

I actually had not realized that I had to use the embed-functionality. I thought that was only for actually embedding 'visual' items.

So, embedding is actually _all_ kinds of integration.

Thanks!

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Mon, 2010-08-30 01:08