Opened 17 years ago
Closed 17 years ago
#5475 closed (fixed)
[patch] Luhn algorithm implementation should be added to Django
Reported by: | Ben Slavin | Owned by: | Ben Slavin |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Keywords: | sprintsept14 | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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)
Change History (8)
by , 17 years ago
Attachment: | ticket_5475__revision_6218.diff added |
---|
comment:1 by , 17 years ago
Status: | new → assigned |
---|---|
Triage Stage: | Unreviewed → Accepted |
Accepting based on status of #3961.
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
This belongs in something like Satchmo -- not in Django itself.
comment:3 by , 17 years ago
Adrian, how do you propose we implement validation for identity numbers (akin to social security numbers) in za localflavour?
comment:4 by , 17 years ago
Resolution: | wontfix |
---|---|
Status: | closed → 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:
- This implementation was suggested by Malcolm (not trying to drag him into a debate here).
- I don't think you understood the reason for the patch before closing it.
- #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:6 by , 17 years ago
Triage Stage: | Accepted → 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 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Added django.utils.checksums, which contains an implementation of the Luhn algorithm. Tests included.