Skip to content
/ ccgen Public

Minimalistic Go package for a random Luhn-compliant credit card numbers generation

License

Notifications You must be signed in to change notification settings

nsuprun/ccgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ccgen

Minimalistic Go package for a random Luhn-compliant credit card numbers generation

Go Report Card Build Status

Introduction

The package allows generating random credit card numbers according to the Luhn algorithm. Card prefix (first N digits of a card number) will correspond to the selected card scheme.

Usage

Install the package with:

go get github.com/nsuprun/ccgen

Import:

import (
	"github.com/nsuprun/ccgen"
)

At the moment the following card schemes are supported:

const (
	AmericanExpress CardType = iota + 1
	DinersClub
	DinersClubUS
	Discover
	JCB
	Laser
	Maestro
	Mastercard
	Solo
	Unionpay
	Visa
	Mir
)
func main() {
	// To generate a card number of a random card type
	fmt.Printf("Random card type number: %s\n", ccgen.Generate())

	// To generate a card number of a choosen type and random valid length
	fmt.Printf("American Express: %s\n", ccgen.AmericanExpress.Generate())
	fmt.Printf("Diners Club: %s\n", ccgen.DinersClub.Generate())

	// To generate a card number of selected valid length:
	// Solo 19 digits card
	fmt.Printf("Solo: %s\n", ccgen.Solo.GenerateOfLength(19))

	// To validate if card number of given type is valid
	fmt.Printf("Card number is valid: %t\n", ccgen.DinersClub.ValidNumber("36690592674457"))
}

Output:

Random card number: 6767575111052941
American Express: 346905926744572
Diners Club: 36690592674457
Solo: 6334690592674457710
Card number is valid: true

About

Minimalistic Go package for a random Luhn-compliant credit card numbers generation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages