-
Notifications
You must be signed in to change notification settings - Fork 129
feat(m4): add solution exe-006 two-word-random-password #3548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlessandroVerzella
wants to merge
7
commits into
tomorrowdevs-projects:main
Choose a base branch
from
AlessandroVerzella:solution/m4-006
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c1bf6ab
added a console.log instruction
AlessandroVerzella 66f5b5d
add a second console log
AlessandroVerzella fb2e8d5
removed console.logs
AlessandroVerzella c08b27c
Aggiunto sample_file.txt
AlessandroVerzella 784da32
Added solution of the exercise
AlessandroVerzella f66a37d
Remove some comments
AlessandroVerzella c2dc899
Added new solution
AlessandroVerzella File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { readFile } = require('fs/promises'); | ||
|
||
let filePath = './sample_file.txt'; | ||
|
||
readFile(filePath) | ||
.then((data) => { | ||
const allTheWordsFile = data | ||
.toString() | ||
.replace(/[0-9.,\/#!$%\^&\*;:{}=\-_`~(),' ', \r\n]/g, ' ') // Remove all characters that are not letters | ||
.split(' ') | ||
.filter((element) => element !== ''); // Don't consider the empty space | ||
|
||
// Pick two random words from the file | ||
const firstWord = | ||
allTheWordsFile[Math.floor(Math.random() * allTheWordsFile.length)]; | ||
const secondWord = | ||
allTheWordsFile[Math.floor(Math.random() * allTheWordsFile.length)]; | ||
|
||
// Capitalise the first letter | ||
const firstWordPassword = | ||
firstWord.charAt(0).toUpperCase() + firstWord.slice(1); | ||
const secondWordPassword = | ||
secondWord.charAt(0).toUpperCase() + secondWord.slice(1); | ||
|
||
// Password with the two random words | ||
const twoWordRandomPassword = | ||
firstWordPassword.concat(secondWordPassword); | ||
|
||
// Check the conditions | ||
if ( | ||
firstWordPassword.length >= 3 && | ||
firstWordPassword.length <= 7 && | ||
secondWordPassword.length >= 3 && | ||
secondWordPassword.length <= 7 && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same suggestion line 17/18. |
||
twoWordRandomPassword.length >= 8 && | ||
twoWordRandomPassword.length <= 10 | ||
) { | ||
console.log(`The password is ${twoWordRandomPassword}`); | ||
} else { | ||
console.log('Password non valida'); | ||
} | ||
}) | ||
.catch((error) => { | ||
console.log('The program is unable to open the file you indicated'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can try to solve the problem and do some refactoring during the mentorship ;-) |
24 changes: 24 additions & 0 deletions
24
projects/m4/006-two-word-random-password/js/sample_file.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Two Word Random Password | ||
|
||
While generating a password by selecting random characters usually creates one that is relatively secure, it also generally gives a password that is difficult to memorize. | ||
|
||
As an alternative, some systems construct a password by taking two English words and concatenating them. While this password may not be as secure, it is normally much easier to memorize. | ||
|
||
Write a program that reads a file containing a list of words, randomly selects two | ||
of them, and concatenates them to produce a new password. | ||
|
||
When producing the password ensure that the total length is between 8 and 10 characters, and that each word used is at least three letters long. | ||
|
||
Capitalize each word in the password so that the user can easily see where one word ends and the next one begins. | ||
|
||
Finally, your program should display the password for the user. | ||
|
||
# Documentation | ||
|
||
For this project solution you may use: | ||
|
||
- Files and Exceptions | ||
|
||
# Deadline | ||
|
||
This project requires to be completed in a maximum of **2 hours** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Two Word Random Password | ||
|
||
While generating a password by selecting random characters usually creates one that is relatively secure, it also generally gives a password that is difficult to memorize. | ||
|
||
As an alternative, some systems construct a password by taking two English words and concatenating them. While this password may not be as secure, it is normally much easier to memorize. | ||
|
||
Write a program that reads a file containing a list of words, randomly selects two | ||
of them, and concatenates them to produce a new password. | ||
|
||
When producing the password ensure that the total length is between 8 and 10 characters, and that each word used is at least three letters long. | ||
|
||
Capitalize each word in the password so that the user can easily see where one word ends and the next one begins. | ||
|
||
Finally, your program should display the password for the user. | ||
|
||
# Documentation | ||
|
||
For this project solution you may use: | ||
|
||
- Files and Exceptions | ||
|
||
# Deadline | ||
|
||
This project requires to be completed in a maximum of **2 hours** |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you perform this check on line 15/16 so that if the password is incorrect, it generates a valid one?
Even better, use a function to achieve this ;-)