Giter Club home page Giter Club logo

ctmutils's Introduction

Package CtmUtils

Set of Go helper functions for random password, keys and IDs generation and verification.

Examples

Password

The function Password generates a random 'password like' string of the length requested in the parameter, using numbers, symbols, upper and lower case characters. The strings does not have any check digit. Useful for encryption passwords, session or cookies ids.

ctmUtils := ctmutils.New()
pass1 := ctmUtils.Password(32)
// PVq-fKv4#@vQV9Js5qsXXYD8LH1C&..f

Key

The function Key generates a random byte key of the length requested in the parameter. The return is a []byte. Useful for unique objects ids.

ctmUtils := ctmutils.New()
key1 := ctmUtils.Key(32)
// de8cbcdd5f73f9901c0c7fe8350693c2e53f8d36dd17a70613c84726372ca40b

ID

The function GenerateID generates a random string in the "AAAA-BBBB-CCCC-DDX" format, where the last is a ISO6346 check digit. Useful for serial numbers, vouchers, etc.

ctmUtils := ctmutils.New()
key1 := ctmUtils.GenerateID()
// V5ZW-UJQ6-2WT6-H55

There is also a validation function:

ctmUtils.ValidateID("V5ZW-UJQ6-2WT6-H55")  --> true if valid

And a pair of Mask / Unmask function to switch between (AAAA-BBBB-CCCC-DDX <--> AAAABBBBCCCCDDX) formats

ctmUtils.MaskID("V5ZWUJQ62WT6H55") --> "V5ZW-UJQ6-2WT6-H55"
ctmUtils.UnmaskID("V5ZW-UJQ6-2WT6-H55")  --> "V5ZWUJQ62WT6H55"

Algorithms

More information about algorithms used can be found in Wikipedia.

https://en.wikipedia.org/wiki/ISO_6346#Check_Digit

ctmutils's People

Contributors

gpascual2 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.