Giter VIP home page Giter VIP logo

safe.js's Introduction

safe.js

Is your password safe? This is a JavaScript fork of safe.

Build Status spm package

Installation

Install with npm:

$ npm install safe.js --save

Install with component(1):

$ component install lepture/safe.js

You can also grab the standalone file:

$ curl https://github.com/lepture/safe.js/blob/master/safe.js

API

var safe = require('safe.js');

safe(password)

Check the safety strength of the password:

safe('password')

// {valid: false, strength: 'simple', message: 'password is too common'}

safe.min

Set the minimal length of the password, default is 4.

safe.min = 6

safe.words

Words hash map which are commonly used. Many thanks to Mark Burnett for the great work on 10000 Top Passwords.

In Node.js environment, safe.words is loaded with the default data. In browsers, you need to load data yourself.

Browser

Here are the tips for browser integration. If you are using the standalone version of safe.js, you need to download the words.json yourself. If you are using component, it is included in the component.json.

Load words data with an AJAX request:

if (!safe.wordsLoaded) {
  // only load data when words not loaded
  request('path/to/words.json', function(words) {
    safe.cache(words);
  });
}

safe.cache(words)

Cache the words in browser's local storage. Words should be a map/dict object.

safe.wordsLoaded

Safe.js will load data from local storage automatically. If data is loaded, this property will be true.

License

BSD

safe.js's People

Contributors

lepture avatar popomore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

safe.js's Issues

standalone version of safe.js > Uncaught ReferenceError: request is not defined

I'm terrible at resolving errors in javascript. Tried using the standalone javascript version. It's probably an obvious fix.

using the standalone version of safe-js as suggested in the readme.
https://github.com/lepture/safe.js/blob/master/safe.js

<html>
  <head>
    <script src="safe.js"></script>
  </head>
  <body>
    <script>
      console.log("password", safe('password'))
    </script>
  </body>
</html>

above works ok but returns

{valid: true, strength: "medium", message: "password is good enough"}

tried using the AJAZ request example provided for browser integration.

    <script>
    if (!safe.wordsLoaded) {
      // only load data when words not loaded
      request('path/to/words.json', function(words) {
        safe.cache(words);
      });
    }
      console.log("password", safe('password'))
    </script>

received this error.

safe_js_password.html:14 Uncaught ReferenceError: request is not defined
    at safe_js_password.html:14
(anonymous) @ safe_js_password.html:14

also tried loading jquery before requesting the words.json file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

and this is where I fall into npm vs javascript in browser hell. (or descend into the stackexchange infinite vortex)

https://stackoverflow.com/questions/42351983/referenceerror-request-is-not-defined

I'm sure it's a 'simple' issue to resolve. Apologies for my dry humour. :)

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.