Giter Club home page Giter Club logo

verificoder's Introduction

Verificoder

Generate your customized Verification Code on .Net Core.

In some cases, you need to create random numbers between 4 and 8 digits, so this package helps you to have a general code generator for all parts of your program in the .NET modular structure.

You can install from Nuget

Authors

Features (Configuration)

  • Code Length
  • Max of digit repeatation
  • Global and Inline Configuration
  • DI (IVerificoder)
  • Caching the code by phone and validation it

Install

Install with Package Manager Console

  Install-Package Verificoder

Add/DI

// default configuration
services.AddVerificoder();
// if you want use customize setting
services.AddVerificoder(options => {
      options.StartWithZero = true; // default is false 
      options.DefaultLength = 5; // default is 5
      options.DefualtMaxRepeatNumber = 2; // default is 1,
      // if you want use scoped code
      options.ScopeCodeAbsoluteExpiration = TimeSpan.FromMinutes(2); // default is TimeSpan.FromMinutes(1) 
});

Usage/Simple mode

private readonly IVerificoder _verificoder;

public AccountController(IVerificoder verificoder)
{
    _verificoder = verificoder;
}

public IActionResult SendVerifyCode(string phone)
{
    var verifyCode = _verificoder.TakeOne();

    var result _smsService.SendSms(phone, $"your account verification code is :{verifyCode}");

    return Ok();
}

Usage/Scoped Mode

private readonly IVerificoder _verificoder;

public AccountController(IVerificoder verificoder)
{
    _verificoder = verificoder;
}

public IActionResult SendVerifyCode(string phone)
{
       // if last code not expired, you can't take new code.
       // you can set Expiration time when adding option to DI, [ScopeCodeAbsoluteExpiration]
       if (_verificoder.CanTakeOnScope(phone))
       {
           var verifyCode = _verificoder.TakeOnScope(phone);
                 
           var message = string
               .Format("your account verification code is :{0}", verifyCode);

           _smsService.SendSms(phone, message);

           return Ok("Code was Sent to the Phone number.");
       }
 
       return BadRequest("You can't ");
}


public IActionResult CreateAccount(string phone,string userValidationCode)
{

        if(!_verificoder.IsValidOnScope(phone,userValidationCode))
        {
            return BadRequest("Please enter valid codes.");
        }

       // other creation account code
}

Inline/Configuration

// length 7 and default max repeat(1)
var verifyCode = _verificoder.TakeOne(7);
// scoped mode
var verifyCode = _verificoder.TakeOnScope(phone,7);



// length 7 and max repeat(3)
var verifyCode = _verificoder.TakeOne(7,3);
// scoped mode
var verifyCode = _verificoder.TakeOnScope(phone,7,3);

verificoder's People

Contributors

thisisnabi 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.