6 kyu
Password generator
719 of 1,440user7657844
Loading description...
Regular Expressions
Security
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Not sure where my previous comment went. But I was able to successfully solve in JavaScript. Wasn't a kata issue. I wasn't meeting the validity requirements of having AT LEAST one of lowercase letter, one uppercase, and one number. I simply overlooked the lowercase requirement...
Hello, when I run my code through VS code it works. But when I test it on here I get this error message:
Traceback (most recent call last): File "/workspace/default/tests.py", line 9, in lower = any(c.islower() for c in pwd) ^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'NoneType' object is not iterable
Please can someone help me?
You are printing instead of returning the results, so by default the
password_gen
function returnsNone
. Do read this on how to write solutions to katas and troubleshoot them on CWThank you! :D
JS tests print AFTER assertion
assertion fails -> exception -> print never happens because exception exited the function early -> no information given to solver what's wrong
the python tests are also written this way but that test framework doesn't exit early on failed assertion (it should though, and it could conceivably change that behaviour)
js update
the test logic remains the same but is rewritten to facilitate the clarified failure messages or because I didn't like how it looked at me
Merged.
in JavaScript:
Passing all 4 tests(10k passwords generated, testing lengths, testing inequality, testing character count) proceeded by 1 fail saying: "Invalid passwords generated!: expected false to be true"
Is there something I'm missing here?
so there are 5 tests total. The one I'm failing is the 'validity' test.. Any information on what this is expecting?
the test code intended to print out failure messages but was written in an incorrect way that used to "work" but now doesn't (specifically there were console.log's after assertions - but a failed assertion raises an exception and thus exits early and skips code after it)
the tests have been updated, they'll now tell you what they don't like.
This comment has been hidden.
Not a kata issue, there are problems with your solution.
Crystal's tests do not check for randomness, also needs a lot of clean-up
Unsolvable in Crystal
The code of Crystal tests is so bad they should be deleted and rewritten for scratch.
Oh it turns out the problem was already reported.
Finally solvable after 3 years, thanks!
Very cool kata, to train about random function ! That's pretty fun (i've done it in js)
Solved, but I'm curious why I can't use console.log() in JS?
What do you mean you can't use it?
Code like this did not print the output from console.log()
I received only messages from test like: "Passwords use a limited characterset!".
You're right, when your code is not ok, the log doesn't show.
Everybody/most of us usually use(s) console.log after receiving error message to check created code, and in this kata is not possible. Why?
This comment has been hidden.
<C++> I think there is some problem in this kata. After Submiting my code I decided to remove the "cout" sections in my code and noticed that it started to not working after that.
Thanks for the kata! Now I have my own password generator :)
Ruby 3.0 should be enabled.
Enabled in this fork
Crystal final test cases are broken for unknown reason.
Translator's solution works, so just GIT GUD :)
This issue got accidentaly re-raised, so I will close this one.
This comment has been hidden.
My code fails one of the final test cases. It says that the password generated is invalid, even though it meets all the criteria in the test cases. I am using python.
Testing for password lengths ... Passwords lengths are not different enough! (6-20 chars)
What?
Solved it: Apperantly a uniform distribution of password lengths is required.
Yeah, I don't know how the author did it, but that test is brilliant.
Ruby checker function is broken: it doesn't check correctly if all passwords contain at least one character from each group.
This comment has been hidden.
Maybe this question can't be answered because it's too revealing, but I must ask anyway.
Coding in C++, using built-in random function and seeding with time. However, when the tests run, it gives the same password every single time. The password looks random, but it is just the same thing over and over again. Not really sure how to get around this because seeding with the time should solve this problem. Any tips?
Are you seeding inside or outside the loop? The former will lead to resetting the randomizer with each loop generating identical results each time.
Seeding outside the loop. First line of code in the function.
You should not seed anything at all.
Also, for some reason even a working solution may not pass the tests (I suspect it's the absence of seeding inside the fixture, though I can't tell for sure).
Same issue here. Everything seems fine in log but I can't pass the bias test. I guess it has something to do with the 50% occurrence limit total. I'm using rand() in C++ to generate random integers to convert to chars, maybe there is a better randomic engine out there?
I have used the standard fix for modulo bias and I still can't get this thing to pass the bias test.
what problem? Completed in 419ms Testing validity ... Test Passed Completed in 1ms Testing for password lengths ... Test Passed Testing for inequality ... Test Passed Testing for character count ... ✘ Passwords use a limited characterset!
Make sure your password can cover all the character set:
I cannot pass "passwords without bias" either. When I am running the code in the terminal, everything looks just fine. For example:
8X35cQ WI5Vf8PDmigB 5mogMnbcCSKeOclGWtb5 0hZilZyFHkB 6S3K299gGma2l3x1 Zgr43aXQ PYfKIe5b guTNEpt8fdQZ3gTi z6wMVvd6QESUGfz0yD VgJEI97ZuCOPgOkkBL0
Does anyone have an idea what exactly this test check?
It tests the frequency of use of each allowed character. In 10000 generated passwords, each allowed character should be used equally often. As there is some randomness, the test allows for a deviation of 50% for each character's frequency from the mean.
In short: you need to make sure that all characters are used with the same probability / frequency.
This comment has been hidden.
Yes, pretty sure the bias test is correct and actually rather lenient.
Try testing your generated passwords yourself. Generate 10000 passwords, count the number of occurences of each allowed character. Check if there are any outliers, that are not produced at a similar rate as the others. For example: if there are 250 occurences of 'a', but only 100 of '1', the code is biased.
How to pass the "passwords without bias" test? What is it testing for?
C++ I'm struggling with this one!
Still can't pass the "should_generate_passwords_without_bias" tests. I'm pretty sure I'm respecting all criterias.
Anyone else having problems in C++ ? I can see that 6 people passed the test, so it has to be me, but still.. :/
Also could you clarify "...all characters should have less than 50% occurance..." What does that mean exaclty ?
Thanks for the help !
"...all characters should have less than 50% occurance..." means, that one character shouldn't appear in string more, than (string.size() / 2) times and i have the same problem with "should_generate_passwords_without_bias" - can anyone explain what it actually means
Regarding the 50% rule, I don't think it is what you describe, since it also says "Based on extensive tests, the normal rate is around 35%" which would'nt make sense since we have 62 characters and only a max length of 20. If it is what you describe, the rate "normal" rate should be much lower.
just I can't see any other sense of that coniditon
maybe author means maximum appearance-rate (ar), like "eR5qeS7en" - 'e' ar is 33%, and it is normal ar maximum for one (or few) symbols ?
Same error here, I can't pass that test. The note about what is considered randomness is extremely vague. I have tried what was suggested above: limiting the number of occurrences of each character in a password to 33% / 50% (tested each), but it still doesn't work.
Any update here? I can't seem to pass the should_generate_passwords_without_bias test. I'm using rand() for random number generation.
I tested my solution and I get uniform distribution of all available characters, and i still don't pass without bias test.
I have the same problem. Slx64, can you verify that your tests are correct for C++?
The test looks correct to me. It tests the frequency of use of each allowed character. In 10000 generated passwords, each allowed character should be used equally often. As there is some randomness, the test allows for a deviation of 50% for each character's frequency from the mean.
In short: you need to make sure that all characters are used with the same probability / frequency.
I found this kata more difficult in javascript as compire to Python !!! Great kata
This comment has been hidden.
I also have 1 test case failing "Passwords lengths are not different enough! (6-20 chars)". I'm not sure what's wrong. Please let me know...
Test Results: Generating 10000 passwords ... Testing validity ... ✔ Test Passed Testing for password lengths ... ✘ Passwords lengths are not different enough! (6-20 chars) Testing for inequality ... ✔ Test Passed Testing for character count ... ✔ Test Passed
Which language?
Python. But I got it solved, my upper limit for the lengh was 1 too low.
Oh, ok, sweet. Cheers
thanks
JS, Ruby and Crystal translations kumited :)
what i do wrong? Generating 10000 passwords ... Testing validity ... ✔ Test Passed Testing for password lengths ... ✘ Passwords lengths are not different enough! (8-20 chars) Testing for inequality ... ✔ Test Passed Testing for character count ... ✔ Test Passed
I believe this means that you're having too restrictive of a length of passwords - should be between 6 and 20, yours look like they are between 8 and 20.
Yes, the description says to create passwords with 6-20 chars. You are creating passwords with 8-20 chars.
Any idea what "Passwords use a limited characterset!" can be fixed by? My code passes all the other tests. I thought we were supposed to use a limited character set, (uppercase, lowercase, and numbers only, as per instructions)
It means that your passwords are not random "enough": it usually happens if you're not using the full character set (there is a check to see if all 26+26+10 characters are present); or you use a limited method, like "1 uppercase + 1 lowercase + random digits".
For the later, the characters used in the generated passwords are counted, and if any character occurs more than 50% of the cases, then the test fails. Based on my tests, the normal appearance rate is around 35%, so there is quite a large margin.
update: I updated the description with this info.
I am using the full character set, not using a limited method, and using random.choice to select both the type (upper, lower, or num) and the selection within that group.
Still not working.
I see you found a working solution in the meantime :-)
I updated the test cases and added an example test case to help the users. I hope I did it right (this is my first kata contribution :-) The final tests should be much more strict now.
Check and let me know if you like it!
Looks great, thank you! :)
This comment has been hidden.
Oh, and you still don't check password length extensively enough: I can pass the kata by creating e.g. only 15+ char passwords (see my new solution ;-)
...and you could display the generated password during the tests, so users can see what's wrong, instead of just "Value is not what was expected".
Cheers
Adding an example test case is impossible with random output but the generated passwords are displayed now.
This comment has been hidden.
The test cases are much harder now.