I started programming in October this year with Python, once I was solid in Python I learned HTML and CSS rather quickly, and now started the EduYoda Javascript course on Udemy (got it free) 2 days ago. Already 40% done with the course, but so far so good!
Assuming you posted the link for feedback on code, here are some suggestions.
None of your variables are ever reassigned. Use const for those.
You've stored the element in passwordinput variable, might use that reference instead of event.target.
It's a good practice use === and !== avoiding implicit casts (unless you need them.
passwordimg.classList.contains('hide') == true is equivalent to passwordimg.classList.contains('hide').
I haven't looked into CSS yet, but you shouldn't have both show and hide classes. Usually people only have hide and if that's not present then the element is visible.
Looked at CSS.
That hiding by translateX should be replaced by display: none or visibility: hidden.
Remove .show, it does nothing. translateY(0) is the default.
The usual convention is to not use units besides a 0.
Looked at HTML.
Try sticking to a consistent quoting strategy. By mixing single and double quotes you leave the impression that you've put this together from different examples.
So instead of event.target .value I can just used passwordinput.value?
Exactly. Of course, that's just a suggestion/alternative. I usually do it when I already know the target beforehand and leave event.target for those cases where that might handle different elements.
This is very impressive after only a few days of learning JavaScript. You clearly have a knack for programming. I feel like shit though because it took me months to do what you've done in days. Nice job though, I just looked at your repo.
Thank you! And if JS was you first programming language, I completely understand.
I bought the Automate the Boring Stuff to learn Python (my first programming language) on Oct 2nd of this year. I started off good but slow, but literally couldn't wrap my mind out of a for loop. I was doing the course for so long and trying to make stuff (literally just print statements and inputs in a little guess the number program lmao, thought that was so damn cool) I burnt out and said f**k this for about 2-2.5 weeks.
Then I got back into it, kept at it, and here I am. After learning the fundamentals well enough, then making your own projects and implementing all you learned---that's how the fundamentals really get engrained.
I used to hear that learning a new language after learning your first well isn't that hard, as you conceptually understand what is happening, it's just a change of grammar, syntax, features, and little nuances specific to that language. 100% true
By the way, do the practice problems he gives in the resources under most of the videos! took long and couldn't some of them because they're pretty hard for a beginner to the language but some made me find the answer on stack overflow and learn about the .filter() like I used in this site to find numbers and specialcharacters! Good luck
No problem! No bad things to say about the JS course except the mic quality isnt that great but it's good enough to be understood.
I use udemyfreebies and check it everyday to see if theres anything I might be interested in and just get it free lol. Start using udemyfreebies, udemy alone wont show you coupon discounts.
When I'm in the course and he shows the basics of say manipulation of HTML element styles a JS or whatever he says for example 'now lets make the font increase when we click this button and decrease when we click this button'
I just pause the vid right there and try to do it myself, If after trying and trying i don't get it then I go on w the vid to see how he did it
Takes much longer but active problem solving is key
Nice! I’ve gotta start learning JS I’ve avoided it for years due to intimidation. Keep it up would love to keep seeing your progress. What are your resources for learning?
Hey! Definitely go for it. I remember before going into any JS i thought what the hell when I saw all the brackets { } everywhere 😂 looked complex. I was coming from a Python only background.
For CSS i also sharpened my skills when I was on the go with a Free app called Programming Hub. Learned a lot of specifics this way actually, like how justify-content differs from align-items depending on if your flex direction is row (on row justify is Y axis, align X axis) and if column (justify is X axis and align is Y axis)
I use this site to get free udemy courses since they are always on sale with coupons:
honestly don't know but most of the time I spend practicing and making little projects to get that 'muscle memory', near 6-8 hours a day between making stuff and actually doing the course.
i spent the day yesterday making these, the calculator was the longest.
oh GOD php was a whole other level, but somehow, I understood php a little bit better than I ever did JS, now I've been so out of it, I probably don't know how much I will remember.
Thanks for the response. My husband has skillshare, so I was thinking of trying some of the courses out there. It's been well over a decade since i've done some serious web dev stuff. Another thing I've always heard was that doing projects is the best way to learn, my thing is I can never seem to figure out a project, I'm most likely overthinking it, but I'm curious how you started off coming up with project ideas? Based off of this project you shared, you just thought of doing your own version of an existing thing in the web dev world?
Isn't it generally good practice to put some sort of reasonable limit on something like passwords (like 128 or 256 characters?) to prevent it becoming a potential avenue for DDoS'ing?
If you don't put any sort of limit on password length, people can then throw arbitrarily large amounts of data at the server via a password field that it then has to hash, which can be computationally expensive, causing issues.
I remember reading some sort of issue caused by having no length limit on passwords somewhere a while back, it might not have been this one but:
Unfortunately, this complexity can also be used as an attack vector. Django does not impose any maximum on the length of the plaintext password, meaning that an attacker can simply submit arbitrarily large—and guaranteed-to-fail—passwords, forcing a server running Django to perform the resulting expensive hash computation in an attempt to check the password. A password one megabyte in size, for example, will require roughly one minute of computation to check when using the PBKDF2 hasher.
This allows for denial-of-service attacks through repeated submission of large passwords, tying up server resources in the expensive computation of the corresponding hashes.
Long passwords are good, but too much length can be a DoS hazard (2013)
Depends on the algorithm. For bcrypt, anything over 72 characters (technically 72 bytes) is going to be truncated so allowing longer passwords isn't adding security.
I like 128 character passwords from password generators. I've seen sites that make a password character limit on the CREATE password field, but not on other fields. This causes huge problems, because you have a long password in your clipboard, paste it into password field, it's accepted, and saved. To the user, they believe their full password in the clipboard was used, so they save it locally or to a password vault. But when they try to use it again, the new password field doesn't accept it, because it stored a truncated version.
That's why when I lowercase & truncate all passwords that come to my app to the first 3 characters (for performance reasons when hashing), I do it server-side so it doesn't impact users.
Also, consider using (only or mainly, depending on your target audience) social login options. There are a ton of options nowadays and it saves you the trouble of storing passwords securely, password requirements, 2FA, forgot password functionality, etc.
Length is one of the most important factors for choosing a good password. Enforcing an arbitraty max length doesn't help anyone. You won't be storing the password in plaintext anyways, so it's not like your database only has 20 characters in the password column or anything.
Yep. Need numbers? “1234” need special characters? “!” Need uppercase “first letter of the password”. Plus now it’s not my usual password ans I already forgot it. (Ps: i use a password generator for anything sensitive) What really works for me is the bar indicating “weak- average”strong” password depending on what I use.
I can see the point of requirements, they will increase security if people don't do what you mention in the second part. A solid middleground is the standard 1 large letter + 1 number + min length.
What I personally (and many people that are actual experts) find most important is information, so giving tips in how to structure passwords is likely more helpful. It would seem the best and least objectionable is giving directions about creating a sentence with a number added somewhere (also why I personally love when "SPACE" is allowed in passwords)
What I personally (and many people that are actual experts) find most important
Please don't appeal to experts without giving actual links to back it up
What you're proposing here does not adhere to current security best practices. In fact, NIST says the complete opposite:
To address... security concerns, online services have introduced rules in an effort to increase the complexity of [passwords]. The most notable form of these is composition rules, which require the user to choose passwords constructed using a mix of character types, such as at least one digit, uppercase letter, and symbol. However, analyses of breached password databases reveal that the benefit of such rules is not nearly as significant as initially thought, although the impact on usability and memorability is severe.
I probably should have worded things differently. I did not mean to pander to experts, nor did I want to say that we shouldn't have the password requirements prevalent today (I mentioned I see the point in them).
One of many people giving the recommendation of using long passwords with a sentence like structure is Snowden. Snowden mentions this in among other places his interview with John Oliver (Last Week Tonight).
Your quote itself actually points out the issues with the requirements: "benefit of such rules is not nearly as significant as initially thought, although the impact on usability and memorability is severe." There is a reason we see people using the same password everywhere (apart from people using a password service).
Hence why I pointed out that inormation about how to structure a memorable and secure password would seem like a smart choice ON TOP OF the current requirements. Just the latter isn't enough.
More importantly, passwords should not be stored in plain text.
Passwords should be hashed before being stored. The length of a string does not affect the length of the hash - therefore, all characters will always be valid.
EDIT: I just realised the comment above mentions exactly that. My bad.
Many tutorials for a Node backend include using bcrypt to hash passwords, however bcrypt ignores everything past 72 bytes. Is it wrong to use brcypt here? Would a better alternative simply be sha256 or something without such a limited input size?
Short answer: use a sane max length (like 200) to avoid denial of service attacks (by posting a 5 GB password) and use sha2 to hash the password before using bcrypt. The sha will ensure that the bcrypt input has a fixed length and bcrypt will limit the brute force feasibility.
You do need a max length to mitigate collission attacks, but it can be in the thousands of characters. 500 to 4K is a decent upper max length. It's also longer than anyone would reasonably want to use so you are safe there.
All hashing algorithms have, by their very nature, collisions. If you allow the input to be longer than the length of the hash. The question is if those collissions can be found reasonably easily... Which for non-broken algorithms they shouldn't be.
Point is, this prevents (or very much limits) that attack vector easily and pre-emptively.
User A sets their password to some value, working with user B to set their password to a different value that ends up with the same hash. That's not a problem. User A intentionally collided their passwords. (second preimage attack)
An attacker gets access to password hashes from your database, and tries to crack them. But for this one user that has a 4 kilobyte password, they can find something that hashes into that password hash, but don't find the actual password. I can't find a single example of this attack being a thing on any cryptographic hashing (password or generic) function ever. Apparently a theoretical one exists for MD4 but if you're using MD4 to store your passwords it's just going to get brute forced on a few GPUs. Worrying about this is like worrying about AES256 being broken.
I really tried to find the original article I read on this and I can't. I might also be misremembering and this might've been about a different issue, like mitigating other types of attacks.
One that comes to mind is DOS by way of supplying huge inputs for the slow hashing functions.
Another might be the simple fact that at some point you have to have an upper bound, and having a large enough but known number makes this actually testable.
One that comes to mind is DOS by way of supplying huge inputs for the slow hashing functions.
I was chatting with other people about this and argon2 at least (and probably others) does a pre-hashing to collapse the input down to a constant length, and then they work on that, so if I wanted to DoS you, it would be best for me to just send you short passwords, since long inputs don't increase the time much. (argon2 uses Blake2 which operates at like 1GB/s on my machine from my crude benchmarks)
There is an issue with PBKDF2 where you shouldn't ask for more output than default since if you do you're wasting time and the attacker can just brute force based on the first block of output. ( https://security.stackexchange.com/a/58450 ) But that only affects asking for a longer output hash, it has nothing to do with the input hash.
Probably not what you meant but interesting regardless.
And yeah, I guess some upper limit is needed, but it should be something that users are absolutely not going to hit, like 64KB or something. As long as the users can enter the password on every client, I don't think an upper limit is really needed.
You're right, but it's not just the hashing functions to consider. You have the application, the language, often a framework between that, various libraries and whatnot, and 64K might be too much for some cases. But as long as you test for whatever number you choose (and it doesn't take too long) in the end it should be fine.
And I found a related article if not the one I was looking for, and it is about mitigating an issue with long inputs for PBKDF2.
Argon2, as a successor of sorts, doesn't seem to have this issue as you point out.
argon2 has no length limit (No limit users are actually going to hit). Or pre-hash it with some other algorithm (bcrypt(SHA512(password))), if you really want to use bcrypt.
The main point was against 20 character passwords, which are in the realm of commonly hit by users subscribing to a correcthorsebatterystaple type of password. My uni uses 13 as a max which I find frankly baffling.
Maybe I made the site in which case the max length might be 32 or 64 characters, which makes hashing easier because I don't really understand that stuff XD
Max length is a pita if I use a generator then those requirements cause problems. If I see them it also begs the question ‘why?’ And seems like a security hole waiting to be found
You're supposed to store a salted hash of the password in the database, and not the raw text itself? Of course I knew that! Laughs nervously in corporate. I just thought I.. er... you might need a reminder some day!
The input string length has no effect on the output hash string length. So passwords don't need a max length (we'll maybe you could cap to a few hundred if you're really worried)
True. Anyone can use Burp Suite etc to intercept request and post inaccurate/malicious stuff. My college had a seminar where a hacker demonstrated how easy it is to bypass simple validations. He booked 12 tickets for a water park for just (1 Rs) worth 799 by intercepting network requests made by browser. Pretty dangerous
But that's exactly what server-side validation should prevent, no? For instance, server should recheck the price and quantity with the database before allowing the checkout, or should not allow an user with no privileges to get a response from the API. Am I missing something?
i'm slowly getting family to use them more and more. they are always like can't remember that though, i'm like its one password of a good difficulty to secure seriously complex one. Even parents and grandparents starting to use more and so less re-use and such overall.
- Using a phone app and keep the data there. - Using a thumb drive with the keepass portable version so you can open it on any computer. - Self hosting keepass online. - Using a different hosted password database.
Depending on your needs though, I may recommend just going old school with a password notebook. Buy a small notebook and keep your passwords in it. Put one account per page, when the password changes just cross it out and write the new one on the next line.
Hard to know the best solution without understanding all of the use cases. All of these are better than re-using passwords across multiple websites or worse using insecure passwords that can be easily cracked.
I posted a few days ago on LinkedIn on how security on the web is broken. And you would've been inspired from some tutorial or course to build a web form. The first example is almost always a login form.
Logging people in is the hardest part and beginners should not be bothered with building one. Almost always use IDPs to authenticate users, even then it's not the best because web security is fundamentally broken. The only advantage is the giants would've faced so many attacks that they are better prepared for it, they would have dedicated teams and budgets to make sure it's always working as intended.
Kudos on the effort, but please stay away from this and keep everyone safe.
You could take a well-known library or framework that you know does security well, look at how they do it and learn from that.
Like, when you implement logging in / security in the PHP framework Symfony, you get to decently low-level stuff since the framework wants you to be able to do anything you want. But the documentation is very good and detailed, and has the most basic use cases laid out for you with links to advanced topics.
So good way to learn this would be to implement security in Symfony, then look at the advanced stuff, which will inevitably lead you to also looking at their source to figure out the implementation details when you need to know them. Their logic isn't even too convoluted anymore, though if you aren't familiar with how Symfony works it might still pose a challenge.
I feel like thats probably the correct answer. If you have the budget to sit and really explore security your probably above Oauth/Auth0 levels anyways
I was in the course and heard the instructor say when talking about the event of 'change' and 'input' for .addEventListener that "this can also be used for password validation so i was like oh shit let me try that"
We had previously just had a lesson regarding checking .classList on a variable to see if it .contains() a class, and if not to add / remove one for the other.
This allowed me to create a JS drop-down menu, using css properties of transform:translateX(-9999px); for hide which was by default a class, and to remove it and add show class which was transform:translateX(0px);, hiding and u hiding the elements automatically
I only ask because you said you were learning JavaScript, but that idea is very coupled to the user interface. When I was learning JS I did a ton of stuff with no interface first. I bet you would like the book: “Exercises for Programmers.”
Oh yeah I definitely practiced non UI stuff, the udemy course gave me practice problems but it was all generally the same as what I know from python, my first language!
Will definitely be using the input type=password. Will add the confirm password thing and the focus.
However, what about just having the text for the rules on the side? When one rule is met, it's text in the list will turn green, and red if not yet met.
And I won't be using this as an actual page lol I will be moving these features you mentioned plus x and check features over to this form I made the other day. Roughly went off a mock up design i found online, just added the social logins.
So there's a bit of a bandwagon here telling you the same thing I was going to say which is don't put restrictions on passwords. If someone is trying to crack passwords, they have less work to do if they can rule out a huge number of passwords. What I didn't see was people telling you what to do instead. The better thing to do is use a library like this: https://github.com/dropbox/zxcvbn
This checks password strength. Validate based on the strength instead. If you want to type 64 lower case letters, that's stronger than Password123!
However, the first one will do well on the validator I posted and the second will not.
I'll also echo other folks and say - great job! It was an awesome learning project and you nailed what you set out to do.
Personally i cannot stand this trend of forcing certain things on passwords. One of those change my view type things. especially length. A hash is the same length at the end of the day when store so don't tell me 6 characters min 20 max type thing. same with numbers and characters etc. I use a password manager, i use strong passwords, don't make me reduce my password strength because someone is stupid enough to use "password" or "1234" as their password.
Good job though OP no criticizing you personally, of course, getting the validation is fun work.
Personally i cannot stand this trend of forcing certain things on passwords.
It's not a trend, it's been a thing since almost forever, and thankfully the trend is to let people use anything they want if it's long enough and not on a list of compromised passwords.
Thankfully even most "official" guidelines support that nowadays.
A hash is the same length at the end of the day when store so don't tell me 6 characters min 20 max type thing.
It's not so long since hashing wasn't even the norm because people who don't understand security implemented their own.
Great job! Awesome feeling isn't it? You learn so much by having to figure out the little things a tutorial just can't prepare you for. Looking forward to seeing more projects from you!
Honestly I havent gotten to regex yet in the JS course I'm taking although I did use it once for one problem where I had to use .replace and .replace all in a string but that's it.
Decided to go with .filter to go through the password input target value on the input event and this works as well so.
I primarily made this to practice the whole .classList.add() / .classList.remove() / .classList.contains() use case of removing and adding a hide and show class for the "x" and check icon as I just learnt how it can be used for menus but this got my wheels turning.
A productive way of asking this question would be;
"That's cool! I think it's great that you are TRYING TO LEARN the very thing we love in here :D :D --- However, I think you should look into "Regex", which you mind find peculiar, but very powerful!"
14
u/[deleted] Dec 28 '20 edited Dec 28 '20
Link to the GitHub repo if anyone is interested in seeing the code:
https://github.com/zeyf/jspasswordvalidation/tree/master
I started programming in October this year with Python, once I was solid in Python I learned HTML and CSS rather quickly, and now started the EduYoda Javascript course on Udemy (got it free) 2 days ago. Already 40% done with the course, but so far so good!
11
u/belkin626 Dec 28 '20
That’s impressive! Always good to get hands dirty than just following a tutorial.
5
u/sfa1985 Dec 28 '20
Nice! I’ve gotta start learning JS I’ve avoided it for years due to intimidation. Keep it up would love to keep seeing your progress. What are your resources for learning?
219
u/JupitersCock Dec 28 '20
Good job! Small side note: please don't give you passwords a max length (like 20 characters) in a real application. That's a bad security practice.
97
u/cguess Dec 28 '20
Good job, just remember to always verify server side as well, client side should only prevent against the most basic possibilities.
47
u/[deleted] Dec 28 '20
Oh I hate those stupid password restrictions.
Password "MyHorseIsGayPeacock" is way more secure than "61;(&ksvOp" and what is unbelievable - you can actually remember it.
14
u/pag07 Dec 28 '20
*uck numbers and special characters. It does not matter.
It's all about password length!
Edit: My 126 characters password got rejected because I didn't have any numbers, on that day I turned into an angry old man.
3
u/TheOnlyLorne Dec 28 '20
Fun fact: you can use <input type='password'></input> to hide the contents
18
u/whizzzkid Dec 28 '20
I posted a few days ago on LinkedIn on how security on the web is broken. And you would've been inspired from some tutorial or course to build a web form. The first example is almost always a login form.
Logging people in is the hardest part and beginners should not be bothered with building one. Almost always use IDPs to authenticate users, even then it's not the best because web security is fundamentally broken. The only advantage is the giants would've faced so many attacks that they are better prepared for it, they would have dedicated teams and budgets to make sure it's always working as intended.
Kudos on the effort, but please stay away from this and keep everyone safe.
1
u/sheriffderek Dec 28 '20
What made you choose that project?
1
u/Sykander- Dec 28 '20
Nice job dude, looks slick. A few suggestions though.
Otherwise, nice work dude! Especially like the little green/red check in the field to inform the user if they passed the rule set.
1
u/Programmer101N Dec 29 '20
Nice Work, Without tutorials, this is good improvement. I recommend you to try NodeJs after learning javascript.
3
u/MrQuickLine front-end Dec 28 '20
So there's a bit of a bandwagon here telling you the same thing I was going to say which is don't put restrictions on passwords. If someone is trying to crack passwords, they have less work to do if they can rule out a huge number of passwords. What I didn't see was people telling you what to do instead. The better thing to do is use a library like this: https://github.com/dropbox/zxcvbn
This checks password strength. Validate based on the strength instead. If you want to type 64 lower case letters, that's stronger than
Password123!However, the first one will do well on the validator I posted and the second will not.
I'll also echo other folks and say - great job! It was an awesome learning project and you nailed what you set out to do.
1
u/yashptel99 Dec 28 '20
After 2 days I was like why does let exist if var is already there?
2
u/dazzaondmic Dec 28 '20
Looks impressive for just a couple of days. Keep learning!
2
u/[deleted] Dec 28 '20
if you are self taught, there is one big rule that's ready to miss: please don't save the passwords!!
1
u/myogeshchavan987 Dec 28 '20
That's awesome. Keep it up 👍
1
u/perryrh0dan Dec 28 '20
That's rly Great man :)
1
u/MrMlST Dec 28 '20
Nice
1
u/cia-incognito Dec 28 '20
Well done!! Keep going!
1
u/cookie_monster_1202 Dec 28 '20
Ive been trying to learn webdev and is going really bad lol
1
u/sowmyasri129 Dec 28 '20
Good job That’s impressive! Keep going.
1
u/rafaelsaback Dec 28 '20
Great job pal! To the stars and beyond! ;)
1
u/[deleted] Dec 28 '20
Personally i cannot stand this trend of forcing certain things on passwords. One of those change my view type things. especially length. A hash is the same length at the end of the day when store so don't tell me 6 characters min 20 max type thing. same with numbers and characters etc. I use a password manager, i use strong passwords, don't make me reduce my password strength because someone is stupid enough to use "password" or "1234" as their password.
Good job though OP no criticizing you personally, of course, getting the validation is fun work.
1
u/UncziPodmore Dec 28 '20
GG
1
u/_bym Dec 28 '20
Live feedback is always appreciated in UI.
1
u/[deleted] Dec 28 '20
On my final project in school I had to that without using div. Was kinda difficult lol
1
u/ryan_holton Dec 28 '20
Well done!
1
u/justingolden21 Dec 28 '20
<input type="password">: )
1
u/fyzbo Dec 28 '20
https://xkcd.com/936/
1
u/[deleted] Dec 28 '20
Skills!
1
u/christianabreu Dec 28 '20
One of the better feelings, Good job, Keep it. 😁😁
1
u/terrance_dev Dec 28 '20
Great man, keep going!
1
u/hansbrixe Dec 28 '20
Great job! Awesome feeling isn't it? You learn so much by having to figure out the little things a tutorial just can't prepare you for. Looking forward to seeing more projects from you!
-2
u/backlashsid Dec 28 '20
Why not use a regex?