Build a Simple Password Generator in Node.js – Coding Shiksha

Build a Simple Password Generator in Node.js – Coding Shiksha

Welcome Folks I am back with another blog post. In this blog post we will be building a simple password generator in Node.js. The whole source code of the application will be given below. You can see the source code and understand it and try to extend it according to your needs.

READ  jQuery FullCalendar Integration Using PHP MySQL & AJAX

 

package.json

 

{
    "name": "simple-password-generator",
    "version": "1.1.0",
    "description": "A simple password generator for Node.js . It allows you to create random and secure passwords on the fly.",
    "keywords": [
        "password",
        "generator",
        "simple"
    ],
    "repository": {
        "type": "git",
        "url": "https://github.com/edmarriner/simple-password-generator.git"
    },
    "author": {
        "name": "EdwardMarriner",
        "email": "edmarriner@gmail.com",
        "url": "http://www.edwardmarriner.co.uk/"
    },
    "licenses": [
        {
            "type": "MIT",
            "url": "https://raw.github.com/edmarriner/simple-password-generator/master/LICENSE"
        }
    ]
}

 

READ  Basic CRUD Application in VUE with Firebase

This is the package json file for the application. It can also be alternatively created by issuing node command such as npm init it will ask basic questions and you have to answer and it will create the file for you.

 

 

!(function(){
	
	var spg = require('./simple-password-generator.js');

	console.log(spg.generate({
		length : 3
	}));

})();

 

READ  How to Transform JSON Objects into HTML Using json2html.js - Coding Shiksha

 

!(function(){
	
	_ = require('lodash-node');

	// Password defaults
	var defaults = {
		length : 8
	};

	/*
	 * Generates a random password.
	 */
	exports.generate = function(userOptions)
	{
		var options = _.assign(defaults, userOptions);

		// Generate a random number.
		var number = Math.random()

		// Convert this number into a string.
		var string = number.toString(36)

		// Grab a section of the string as the password
		var password = string.slice(-defaults['length']);

		// Return the password back!
		return password;
	}

})();

 

Download Source Code

 

Leave a Reply

Close Menu

Indian Desi Tools - Ultimate Tools Website

Demo Description


This will close in 20 seconds