mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Fix the card validator.
This commit is contained in:
@@ -193,13 +193,28 @@ CardValidationResult ValidateCard(const QString &number) {
|
|||||||
}
|
}
|
||||||
const auto range = MostSpecificBinRangeForNumber(sanitized);
|
const auto range = MostSpecificBinRangeForNumber(sanitized);
|
||||||
const auto brand = range.brand;
|
const auto brand = range.brand;
|
||||||
//if (sanitized.size() > range.length) {
|
|
||||||
// return { .state = ValidationState::Invalid, .brand = brand };
|
static const auto &all = AllRanges();
|
||||||
//} else if (sanitized.size() < range.length) {
|
static const auto compare = [](const BinRange &a, const BinRange &b) {
|
||||||
// return { .state = ValidationState::Incomplete, .brand = brand };
|
return a.length < b.length;
|
||||||
//} else
|
};
|
||||||
if (!IsValidLuhn(sanitized)) {
|
static const auto kMinLength = std::min_element(
|
||||||
|
begin(all),
|
||||||
|
end(all),
|
||||||
|
compare)->length;
|
||||||
|
static const auto kMaxLength = std::max_element(
|
||||||
|
begin(all),
|
||||||
|
end(all),
|
||||||
|
compare)->length;
|
||||||
|
|
||||||
|
if (sanitized.size() > kMaxLength) {
|
||||||
return { .state = ValidationState::Invalid, .brand = brand };
|
return { .state = ValidationState::Invalid, .brand = brand };
|
||||||
|
} else if (sanitized.size() < kMinLength) {
|
||||||
|
return { .state = ValidationState::Incomplete, .brand = brand };
|
||||||
|
} else if (!IsValidLuhn(sanitized)) {
|
||||||
|
return { .state = ValidationState::Invalid, .brand = brand };
|
||||||
|
} else if (sanitized.size() < kMaxLength) {
|
||||||
|
return { .state = ValidationState::Valid, .brand = brand };
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
.state = ValidationState::Valid,
|
.state = ValidationState::Valid,
|
||||||
|
Reference in New Issue
Block a user