mdomke / schwifty

IBAN parsing and validation
https://schwifty.readthedocs.io
MIT License
206 stars 80 forks source link

Generate NL IBAN may generate invalid IBAN #180

Closed pe2mbs closed 9 months ago

pe2mbs commented 9 months ago

When IBAN.generate( country_code = 'NL', ank_code = 'INGB', account_code = str( i ) ) may generate an IBAN thats not 11-proof, which is required by Dutch banks, neither an exception is throw on an invalid account_code.

Also the IBAN.validate() function does not detect a non 11-proof account_code.

Natim commented 9 months ago

@pe2mbs can you share an example of valid and invalid IBANs?

Would you be willing to open a PR that would fix the issue? I can help with testing if you want.

mdomke commented 9 months ago

@pe2mbs You can still use

from schwifty import IBAN
from schwifty import SchwiftyException

valid: list[IBAN] = []
for i in range(1, n):
    iban = IBAN("NL", "INGB", str(i))
    try:
        iban.validate(validate_bban=True)
    except SchwiftyException:
        continue
    else:
        valid.append(iban)

to generate random IBANs. The validate_bban-parameter will validate the national checksum digits.