npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-security-code

v0.0.2

Published

A simple security code generator based on redis client.

Downloads

1

Readme

redis-security-code

NPM License

A simple security code generator based on redis client. Security code, Verify, Verification code, 验证码.

Install

npm install redis-security-code --save

中文说明

基于 Redis 的验证码生成器。 由于在 APP 和 H5 应用中,经常有需要向手机号发送验证码的需求。本模块利用已有的 RedisClient 来迅速的创建验证码,并提供标记TAG,及验证的功能。

推荐您使用 TAG 针对一个手机号标记不同类型的验证码。(如:用于注册,登录,忘记密码等等。)

API

  • init RedisSecurityCode.init(options)

    • options: 参数设置
      • client: 一个合法的RedisClient,可以由redis创建
      • ttl: 验证码的过期时间,默认为10分钟。
      • length: 验证码的长度,默认为6位。
  • generateForTag RedisSecurityCode.generateForTag(key, tag, cb)

    • key: 键,通常是手机号
    • tag: 类型标志(推荐)
    • cb(err, code): 回调函数
      • err: 返回错误
      • code: 验证码
  • verifyForTag RedisSecurityCode.verifyForTag(key, tag, code, cb)

    • key: 键,通常是手机号
    • tag: 类型标志(推荐)
    • code: 用于验证的验证码,由用户输入
    • cb(err, result): 回调函数
      • err: 返回错误
      • result: { match: true | false }matchtrue时,验证成功。
  • generate RedisSecurityCode.generate(key, cb): same as generateForTag without tag

  • verify RedisSecurityCode.verify(key, code, cb): same as verifyForTag without tag

示例

'use strict';

var RedisSecurityCode = require('redis-security-code');
var redisHelper = require('./redis');

RedisSecurityCode.init({
    client: redisHelper.getCodeClient(),    // a redis client is required.
    ttl: 10 * 60   // = 10 mins. Default
});

var TAG = {
    REGISTER: 'register',
    FIND_PASSWORD: 'find_password'
};

module.exports.TAG = TAG;

module.exports.generateRegisterCode = function(phoneNumber, callback) {
    RedisSecurityCode.generateForTag(phoneNumber, TAG.REGISTER, callback);
};

module.exports.verifyRegisterCode = function(phoneNumber, code, callback) {
    RedisSecurityCode.verifyForTag(phoneNumber, TAG.REGISTER, code, callback);
};

module.exports.generateFindPwdCode = function(phoneNumber, callback) {
    RedisSecurityCode.generateForTag(phoneNumber, TAG.FIND_PASSWORD, callback);
};

module.exports.verifyFindPwdCode = function(phoneNumber, code, callback) {
    RedisSecurityCode.verifyForTag(phoneNumber, TAG.FIND_PASSWORD, code, callback);
};