CakePHP 2.3 cookies and Django 1.4 password reset

Published: 2013-05-05
Tagged: django

This is more of a note to self than anything else, really. Time is unforgiving and I get tired of looking up the same sites about how to reset my Django password because I forgot it out of disuse. I'm also exploring the world of cookie and javascript, so I wanted to do a little code dump before these snippets get buried in my coils.

CakePHP 2.3 cookies


Will read a cookie called 'data'. Fairly simple.


This will check if a cookie exists. Useful.

this->Cookie->name = 'data';
$this->Cookie->time = 300;
$this->Cookie->path = '/';
$this->Cookie->domain = '';
$this->Cookie->key = 'data';

This is pretty self explanatory. It creates cookie attributes. What eludes me is the fact that I don't remember if the time is in seconds or milliseconds? I'd bet it's the first one. Now, to actually write that cookie:

$this->Cookie->write('data', 'true', false, 3600)

The first attribute is the key to use, the second the value, the third decided whether the cookie is encrypted (using cake's config.php salt), the last value is the expiry. I guess it's in seconds. What a relief.

I've found this method to be more elegant when handling cookies, but using JavaScript appears to be more elastic and it's a bit less server calls. CakePHP's methods would be good for heavier stuff that has to be handled by controllers, where JS seems good for taking care of those cookies with a lesser responsibility in the grand scheme of things.

To keep things complete, here's how I do cookie using JavaScript:

//get the right date format for cookie
//note how getTime() uses milliseconds instead of seconds
var date = new Date();
expires = 'expires=' + date.toGMTString() + ';';
document.cookie = 'CookieName[key]=value;' + expires + 'path=/;';

Django Password Reset

When using Heroku, use the run command with the --app parameter to invoke a command like so:

heroku run --app appName python changepassword admin

Gotta look into Heroku's manual and check how to specify an app so as to ignore using --app every single time.

And that's all folks!

Hi, I'm Matt.

This blog is an unordered set of thoughts extracted from the mind of a software developer.

About Me PGP key

Archives  Feed  The Photolog!  t: pr0tagon1st