100 days of code #2
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.
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\
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