100 days of code #2

@moneyphotos

day #2 of the 100 days journey. Today I made a simple password-generating website, it was a great project, I discovered much amazing stuff about Javascript.

Daniele Franchi

Concept

The concept behind it is really simple and forward. I wanted to first generate a random set of characters as the password accordingly I put all the characters I wanted to randomize ins variable arrays then used the ‘Math’ function to randomize my pick

// random operator
let op = [“+”, “*”, “/”, “-”];

//random character
let ch = [“!”, “@”, “&”, “#”, “%”, “-”, “/”, “\\”];

// random number
let no = [“0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”];

let rndOp = op[Math.floor(Math.random() * op.length)];

let rndCh = ch[Math.floor(Math.random() * ch.length)];

let rndNo = no[Math.floor(Math.random() * no.length)];

+@ky3ltoe25@5156KY3LTOE25\

Emily Morter

I tested it a couple of times until I met a critical issue, the passwords are random but not unique, in other words, can be generated more than once and that's not what I wanted. I found the ‘new Date()’ function that gets the current date which was a great start but the date itself wasn’t really random or secured. When I made some deeper searching on how to hash a value, I thought it was going to be as easy as python’s hash() but apparently, it wasn't, the only way I found it to be easy enough for me was by using ‘toString’ function, apart from the security issues with this method it was the easiest one

let date = (+new Date()).toString(36);

// a little bit of delay here to make it even harder to crack

let dateDelayed = setTimeout(function () {
date;
}, 5000);

This was basically the core functionality, as easy as it sounds it took me a ton of research and numerous numbers stack overflow issues. here's the codepen for the live demo

Hope you learned a thing or two from this simple project as I did

--

--

--

programmer, book nerd, and a website developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Inelegant Part of React Hooks

Learning React? Here are the things I’d do differently…

From JavaScript to TypeScript — A Typical Journey

Production ready Angular CLI v1.0.0 with i18n and Localised URLS

The #1 Best Design Pattern for Managing Forms in React

How to Refactor Your Complex Nested ‘if-else’ Code?

How to use external CSS in node.js with express

Loops in Javascript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Moayed Ellah

Moayed Ellah

programmer, book nerd, and a website developer

More from Medium

The Coding Survival Guide.

5 Skills You Need to Become a Back End Developer in 2022

Beginner coding & the anti-perfectionist challenge: Day 0

An opened, old journal with handwriting filling both pages.

How does YouTube videos help me become a developer without a computer science degree?