Archive for the 'PHP' Category

Jan 17 2009

Posted by coen under PHP,Programming,School

php and ssha ldap passwords

Although the current semester is almost over, we’re still working very hard on our project (in Dutch), and today I finished a password reset function for users of the portal. The tricky thing for me is that the user passwords are stored in LDAP, so I had to figure out how to write to a LDAP database, and how to create a SSHA password hash in php.
I found that there is very little documentation about the ldap functionality in php, let alone how to create a SSHA hash. There was, however, one post on php.net where I found half of my answer: http://nl.php.net/manual/en/function.sha1.php#52365 . The only thing I had to change was:

// this
$salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand());
// into this
$salt = pack("CCCCCCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());

So, the complete code now looks like this:

mt_srand((double)microtime()*1000000);
$salt = pack("CCCCCCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand());
$sshaPassword = "{SSHA}" . base64_encode( pack("H*", sha1($newpasswd . $salt)) . $salt);
// bind using the configged options
$ldap->bind();
$ldap->save($userDn , array("userPassword" => $sshaPassword));

So finally, the password reset functionality works and users won’t have to worry if they’ve lost their password.

2 Comments »

Apr 04 2008

Posted by coen under PHP,School

HULK all the way

Busy, busy, busy was the theme of my daily life the last few weeks. And actually, I think that it will be like that until school is finished in the summer break. But, there is some news (and that’s why I am writing this post. Surprise, huh?). The logbook I wrote about is finally ready for it’s first use, and will get some really cool features in the near future, like Ldap authentication and after that maybe also authorization.

The HUbuntu project started last week (actually, it hasn’t gotten off it’s feet for a few weeks), and at the moment we are thinking about how to implement easy access to our own repository. In this repository students will be able to find all the software they need for the courses given at the HU, and we want to make that process really easy for them. We already came up with the principal of meta-packages, and today I did some research in that area. The idea is to create a meta-package for each course and determine the right dependencies for that course. I think that a lot of work has to be done, but the general idea is finished. Yay, isn’t that great?

I also made some progress with my or-mapping. For mattijs’ peace I will post a link to the Object class, just as he asked me to: link. It is password-protected, but if you ask nicely, I will provide you with an account. If you create an Object containing an array of Objects in it, the intermediate tables that are needed are now automagically created, but I still have to build that for arrays of primitive PHP types.

4 Comments »

Feb 16 2008

Posted by coen under General,PHP,c++

About how school can be enjoyed again

Finally I have some time to write another post to you, my dear readers!

After starting up the HULK for about a fortnight, we started to bring up ideas for projects (so if anyone has an idea…). Actually, while I’m writing this I realize that I haven’t told you anything yet about the HULK (hmm.. weird).
Well, HULK stands for Hogeschool Utrecht Linux Kennisgroep, and consists of a few classmates and yours truly, who try to give Linux a shot in our university, the Hogeschool of Utrecht. The website is in Dutch, so if you want to follow up on it, you have to be able to read it.

We thought about some really cool projects like building our own Ubuntu distribution, HUbuntu , setting up Linux on mobile devices, teaching Unix, and also some smaller projects like building a logbook to keep track of what we’re doing and to provide student services (SSH access, web servers, database servers, etc.). Apart from that, I’ve started learning c(++), and for practice I’m building an IRC client, called skaar.

Next week, together with Mattijs, I’m starting on the logbook which will be built in PHP, so that we can start logging quickly.

Keeping you posted!

4 Comments »

Dec 29 2007

Posted by coen under PHP

One step at a time

Some time ago I wrote about some great plans for writing an or-mapping. Well, today, I actually made some progress!

Before I started to write on this code, I divided it in three parts:

  1. Creating Objects
  2. Updating Objects
  3. Deleting Objects

I finished a test version of the first part today. Basically, this is how it works: There is a class Object that should be extended by every class that has to be in a database. If you create a class extending this one, it will also be created in the database (if it doesn’t exist yet) as a table. For example, see this class:

 

/**
 * foo
 * bar
 * @table_name=__TEST__
 *
 */
class Test extends Object {    
     /**
     * @nullable = false
     */
    private $firstname; 

    private $lastname; 

    /**
    * @type = string(12)
    * @nullable = false
    */
    private $dateofbirth; 

    private $city; 

    function __construct() {
       parent::__construct();
   } 

    public function getFirstName(){
   	return $this->firstname;
   } 

    public function setFirstname($firstname){
   	$this->firstname = $firstname;
   } 

    public function getLastname(){
   	return $this->lastname;
   } 

    public function setLastname($lastname){
   	$this->lastname = $lastname;
   } 

    public function getDateofbirth(){
   	return $this->dateofbirth;
   } 

    public function setDateofbirth($dob){
   	$this->dateofbirth = $dob;
   } 

    public function getCity(){
   	return $this->city;
   } 

    public function setCity($city){
   	$this->city = $city;
   }
}

Will result in this table:
table screenie


Pretty cool, huh? I still have to do some work, but the base is there. As you can see, you can also use some kind of annotations to set the information for the table and the columns in the database, but there are also default settings if they are omitted.
Enough for today, I’m going to celebrate my weekend and “Oud & nieuw”, as we call New Year’s Eve in Holland :) Soon more about this!

6 Comments »

Dec 18 2007

Posted by coen under PHP

Great plans

In the 2nd year of my study at the HU we learned about J2EE, in particular EJB. Happy with the general idea of never writing another line of SQL, we started doing our school projects with EJB. However it’s true that you don’t write SQL, there is EJB-QL, which looks a darn lot like SQL.
While I like the concept, I wonder if Java is the right language to use. I can’t help thinking about all the layers my poor code has to go through, and how can that ever be fast? Anyway, according to this test, Java is way faster than PHP, which was originally intended for the web (Wikipedia also has a nice comparison about this).

Strangely enough, at that time there was no framework or abstraction layer available for PHP, so I started building one myself. The idea was for it to work like EJB, and the result was satisfactory. Then doom hit me, because I lost all that code :( So now I’m going to start all over again, with a slightly different angle: I am going to write a framework that communicates with the Zend Framework, but with a little extra: the Zend Framework does not provide creation and automatic querying for your objects in the database, and that’s what will be the extra in my framework.

1 Comment »