TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-02-2009, 04:03 PM   #21 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Have you guys checked the date of this thread? It's more than 1 year old, surely he must have removed the file by now.

It's always funny to find old threads, make a post and wonder where everyone is that was originally involved, or asking for files that are old..

I know when I go through an old thread I find interesting, I hope the OP is still around to answer my question!
allworknoplay is offline  
Reply With Quote
Old 05-02-2009, 04:59 PM   #22 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
sketchMedia u are a saviour. The fact that it just completely wouldnt work when it had worked for so many others made me think i was going to have to change a setting in my php.ini file or apache config but never crossed my mind about that one. Its now working. Thanks for your help.
Glad to be of help.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 05-09-2009, 09:00 AM   #23 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Apologies for again being on asking stoopid questions on this one but I cant seem to get the verifyLogin method to work correctly i.e. I have set up my table

CREATE TABLE visionire
(username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
IP VARCHAR(20) NOT NULL,
PRIMARY KEY (username));

and added a row however when I run the script and try and log in the following query always returns no rows:

$query = sprintf("SELECT * FROM user WHERE username = '%s' AND password = sha1('%s') LIMIT 0,1", $this->clean($username), $this->clean($password));

If i rewrite the query and hardcode the user details it works ok so I am assuming its something to do with the way i have defined the columns on the table or how the strings are handled i dunno any experts out there who can spot an error?

Cheers.
captainmerton is offline  
Reply With Quote
Old 05-09-2009, 12:42 PM   #24 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
Apologies for again being on asking stoopid questions on this one but I cant seem to get the verifyLogin method to work correctly i.e. I have set up my table

CREATE TABLE visionire
(username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
IP VARCHAR(20) NOT NULL,
PRIMARY KEY (username));

and added a row however when I run the script and try and log in the following query always returns no rows:

$query = sprintf("SELECT * FROM user WHERE username = '%s' AND password = sha1('%s') LIMIT 0,1", $this->clean($username), $this->clean($password));

If i rewrite the query and hardcode the user details it works ok so I am assuming its something to do with the way i have defined the columns on the table or how the strings are handled i dunno any experts out there who can spot an error?

Cheers.

Well, I'm no OO expert but I don't see where

$this->clean() is defined anywhere?

So it would probably work if you just left that out and put username and password in there like this:


$query = sprintf("SELECT * FROM user WHERE username = '%s' AND password = sha1('%s') LIMIT 0,1", $username, $password);
allworknoplay is offline  
Reply With Quote
Old 05-09-2009, 12:52 PM   #25 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Sorry, found the function all the way on the bottom of the script....

So not sure what it could be....
allworknoplay is offline  
Reply With Quote
Old 05-09-2009, 01:16 PM   #26 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Maybe these 2 properties need to be made public?

/* The username of a member */
private $username;

/* The password of a member */
private $password;
allworknoplay is offline  
Reply With Quote
Old 05-09-2009, 02:04 PM   #27 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Tried to changing them both to public and it had no effect it is still returning no rows on the select.
captainmerton is offline  
Reply With Quote
Old 05-09-2009, 02:08 PM   #28 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Just resolved it:

Removed the sha1 function on the password string. Any ideas what this is for anyway I believe it converts a string to hex or something?
captainmerton is offline  
Reply With Quote
Old 05-09-2009, 02:13 PM   #29 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
Just resolved it:

Removed the sha1 function on the password string. Any ideas what this is for anyway I believe it converts a string to hex or something?

Yeah that's for encryption I think. So are you storing your passwords as raw text?

What is your password column set as? Binary or varchar?
allworknoplay is offline  
Reply With Quote
Old 05-09-2009, 02:28 PM   #30 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Varchar. Not sure it really matters to me if they are encrypted or not.
captainmerton is offline  
Reply With Quote
Old 05-09-2009, 02:29 PM   #31 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
Varchar. Not sure it really matters to me if they are encrypted or not.
Well if you're just messin' around, it doesn't matter...

But of course if your hosting anything meaningful you probably want to go the MD5 route...
allworknoplay is offline  
Reply With Quote
Old 05-09-2009, 02:47 PM   #32 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Whats MD5? I assume I would encrypt the password then store it on the database then unencrypt after i've read it from the database.
captainmerton is offline  
Reply With Quote
Old 05-09-2009, 02:50 PM   #33 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by captainmerton View Post
Whats MD5? I assume I would encrypt the password then store it on the database then unencrypt after i've read it from the database.
yeah you can do that with mcrypt if you have that extension installed.

http://us.php.net/mcrypt

But the best route is to one-way hash it with MD5 so that there is no way to display the password ever...

If a user forgets, they would have to come up with a new password.
allworknoplay is offline  
Reply With Quote
Old 05-15-2009, 02:10 AM   #34 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 14
Thanks: 0
baseballplayr is on a distinguished road
Default

Can anyone point to a spot to download this script? Thanks. :)
baseballplayr is offline  
Reply With Quote
Old 05-15-2009, 02:39 PM   #35 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

@baseballplayr The code is available as an attachment to the first post.
Salathe is offline  
Reply With Quote
Old 05-15-2009, 03:20 PM   #36 (permalink)
The Wanderer
 
Join Date: May 2009
Posts: 14
Thanks: 0
baseballplayr is on a distinguished road
Default

Above the attachment is a v2 that the link is broken on. Does anyone have that?
baseballplayr is offline  
Reply With Quote
Old 05-15-2009, 04:51 PM   #37 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Sadly not. I don't have it. I have sent him an email to see if he has it. Let's hope he does!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-16-2009, 10:50 AM   #38 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

I've been mucking about with this login class and have been starting to make some alterations. Wondered if i pick some more advanced php-ers brains. I want to verify someone is logged in without creating an object so I changed the verifyAccess method to static and call it like this:

/* Verify access */
Login::verifyAccess();
if (false)
{
$login = new Login;

/* Include the HTML for the form */
require_once('./lib/form.php');
}

Any thoughts on this? When you declare a method as static does that mean you are allowing it to be called when there is no object instantiated or specifying it can ONLY be called when no object is instantiated?

Also - any thoughts on the difference between using sessions as opposed to cookies to manage logins. I've always used cookies in the past and i know sessions are server side and probably safer but in my use of this script i want a user "logged in" indefinitely so once they log in they'll never have to login again unless they logout. I know a cookie is perfect for this as i've done it before maybe setting the cookie expiry for a year or something but can I do the same thing with a session or is it ill-suited as essentially you are storing such data on the server? Any advice on this? Cheers.
captainmerton is offline  
Reply With Quote
Old 05-23-2009, 02:25 AM   #39 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You could, if you think it warrants it, convert the class to a singleton. I doubt you're going to want more than one instance of the login class, and so it does make sense to convert it to a singleton class as shown below.

I am not a lover of making all the functions static because you get rid of the ability to have member functions, saved states, and all the other OOP features. I use static functions as namespaces. Now that the new version of PHP will have namespaces, I doubt I'll be using static functions ever again.

When I say static functions, you will need one to make the singleton work, and this is more than fine. The getInstance function returns the object. By setting the constructor to private you're unable to initiate the class by using new.

php Code:
class TalkPHP_Singleton
{
    private static $m_pInstance;
    private $m_szHello;
   
    /* Prevent external initiation but still called. */
    private function __construct()
    {
        $this->m_szHello = 'Hello';
    }
   
    /**
     * @return TalkPHP_Singleton
     */

    public static function getInstance()
    {
        if (empty(self::$m_pInstance))
        {
            /* self() being this class we're in. */
            self::$m_pInstance = new self();
        }
       
        return self::$m_pInstance;
    }
   
    public function getHello($szName)
    {
        return sprintf('Hello %s!', $szName);
    }
}

echo TalkPHP_Singleton::getInstance()->getHello('Adam');
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 05-25-2009, 07:15 PM   #40 (permalink)
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default

Thanks! This should surely learn me something about the use of classes, thanks for the comments in the code as well!

I've been looking through the code, and it all seems understandable! But, I have some trouble with this code:
PHP Code:
    catch(Exception $error) {
        print 
$error->getMessage();
    } 
What does it do? And where is "getMessage()" function defined?

Thanks. :)
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:27 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design