Code

Opened 7 years ago

Closed 7 years ago

#5475 closed (fixed)

[patch] Luhn algorithm implementation should be added to Django

Reported by: __hawkeye__ Owned by: __hawkeye__
Component: Internationalization Version: master
Severity: Keywords: sprintsept14
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The Luhn algorithm is used for validating credit cards and numerous national ID numbers. Django should have a built-in implementation to enable localflavors to add functionality.

Factored out of #3961 to separate additions. Slight implementation details have been changed.

Re: discussion there, the Luhn algorithm works from right to left, so strings are used for processing. Quick (non-scientific) benchmarking shows this string-based method to be faster than other Python implementations available online.

Note: filed under 'internationalization', but arguments could be made for other categorizations.

Attachments (1)

ticket_5475__revision_6218.diff (2.4 KB) - added by __hawkeye__ 7 years ago.
Added django.utils.checksums, which contains an implementation of the Luhn algorithm. Tests included.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by __hawkeye__

Added django.utils.checksums, which contains an implementation of the Luhn algorithm. Tests included.

comment:1 Changed 7 years ago by __hawkeye__

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

Accepting based on status of #3961.

comment:2 Changed 7 years ago by adrian

  • Resolution set to wontfix
  • Status changed from assigned to closed

This belongs in something like Satchmo -- not in Django itself.

comment:3 Changed 7 years ago by russell@…

Adrian, how do you propose we implement validation for identity numbers (akin to social security numbers) in za localflavour?

comment:4 Changed 7 years ago by __hawkeye__

  • Resolution wontfix deleted
  • Status changed from closed to reopened

Adrian, I appreciate your rejection of this based on the credit card aspect, but as Russell mentions, you neglect to consider the other applications.

Both Canada and South Africa use the Luhn algorithm for their national identification numbers. I'm fairly certain that other countries do as well. If the US localflavor gets a USSocialSecurityNumberField, I think it's fair to provide this functionality.

I'm reopening because:

  1. This implementation was suggested by Malcolm (not trying to drag him into a debate here).
  2. I don't think you understood the reason for the patch before closing it.
  3. #3961 (za localflavor) depends on this patch.

I won't reopen again if you still feel it should be closed, but I want to make sure appropriate attention is given.

comment:5 Changed 7 years ago by adrian

Ah, good point -- I was wrong in closing this. My apologies!

comment:6 Changed 7 years ago by Fredrik Lundh <fredrik@…>

  • Triage Stage changed from Accepted to Ready for checkin

For the record, this is used for lots of stuff in Sweden, including "person numbers" (SSN), postgiro/bankgiro codes, OCR payment codes, etc.

(But I have to admit that I've never heard it called "Luhn" before -- the formal name here is "the modulus-10 method with weights 1 and 2". You'll learn something every day ;-)

Anyway, check it in already!

comment:7 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6569]) Fixed #5475 -- Added the Luhn check algorithm to django.utils.checksums so that
localflavors don't have to reimplement it each time. Thanks, hawkeye.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.