[help] passing a md5 digest string into URL

311 views
Skip to first unread message

Giuseppe Franchi

unread,
Feb 27, 2007, 4:53:54 AM2/27/07
to Django users
Hello everyone... again. :)
As i said, i need to pass in my URL a <code> variable, wich is the
result of a md5 digest.
(no private information... only a validation key).

Obviously i tried with
(r'^users/activate_user/(?P<code>)/', 'views.register'),
(r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
'views.register'),
but it doesn't work: Django always return 404.

Is it an encoding problem or something? Any idea on how should i do?

Cheers (and grateful thanks, this group is greatly useful)

ScottB

unread,
Feb 27, 2007, 11:11:40 AM2/27/07
to Django users
Hi Giuseppe.

> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).
>
> Obviously i tried with
> (r'^users/activate_user/(?P<code>)/', 'views.register'),
> (r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
> 'views.register'),
> but it doesn't work: Django always return 404.

It works for me if the code ends with a single equals sign.
e.g.
http://localhost/users/activate_user/abc123=/

If you're stuck, maybe you could post a couple of example urls that
give you 404 errors.

Scott

Giuseppe Franchi

unread,
Mar 1, 2007, 9:38:35 AM3/1/07
to Django users
Cheers, thanks a lot Scott, you were right and i resolved ^^

I post, maybe someone could find it useful.
In my view i used the base64 library.

import md5, base64
...
key = md5.new(string).digest()
key = base64.urlsafe_b64encode(key)
validation.md5_key = key
validation.save()


The URL is
(r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+==)/',
'views.activate_user'),

the final '+==' make it works, as any key generated this way ends with
2 equal signs.

On 27 Feb, 17:11, "ScottB" <tepidr...@gmail.com> wrote:
> Hi Giuseppe.
>
> > As i said, i need to pass in my URL a <code> variable, wich is the
> > result of a md5 digest.
> > (no private information... only a validation key).
>
> > Obviously i tried with
> > (r'^users/activate_user/(?P<code>)/', 'views.register'),
> > (r'^users/activate_user/(?P<code>[a-zA-Z0-9%\-]+=)/',
> > 'views.register'),
> > but it doesn't work: Django always return 404.
>
> It works for me if the code ends with a single equals sign.

> e.g.http://localhost/users/activate_user/abc123=/

Bob

unread,
Mar 1, 2007, 12:52:31 PM3/1/07
to Django users
You can also do this as:
(r^users/activate_user/(?P<code>[^/])/, views.activate_user')
which gets you away from relying on the final equal signs, though it
would allow any characters into the code other than a slash. That
should be okay since the code would not be correct in that case.
- Bob

James Bennett

unread,
Mar 1, 2007, 12:57:40 PM3/1/07
to django...@googlegroups.com
On 2/27/07, Giuseppe Franchi <kors...@hotmail.com> wrote:
> Hello everyone... again. :)
> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).

An md5 hex digest is always 32 characters long, containing digits and
letters A through F, so something like

[a-fA-F0-9]{32}

is about as exact a regex for matching it as you'll find.

SHA1 has the same character range -- [a-fA-F0-9] -- but is forty
characters long.

--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

Jens Diemer

unread,
Mar 2, 2007, 2:31:42 AM3/2/07
to django...@googlegroups.com
Giuseppe Franchi schrieb:

> As i said, i need to pass in my URL a <code> variable, wich is the
> result of a md5 digest.
> (no private information... only a validation key).

Look at this: http://code.google.com/p/django-registration/
and this: http://django-registration.googlecode.com/svn/trunk/urls.py

--
Mfg.

Jens Diemer


----
CMS in pure Python CGI: http://www.pylucid.org

Reply all
Reply to author
Forward
0 new messages