basic password generator
This commit is contained in:
parent
25ddac10df
commit
90535e3237
33
Tasks.md
33
Tasks.md
|
@ -166,3 +166,36 @@ Take a look at the provided Code Example.
|
|||
[Code Example](src/miniweb.py)
|
||||
|
||||
</details>
|
||||
|
||||
## Random Password generator
|
||||
|
||||
Difficulty: 2/5
|
||||
|
||||
1. Generate a string of 16 random alphanumeric characters.
|
||||
2. When starting your script, take a number for a CLI Argument. Generate a random string of this
|
||||
length.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
$ python ./randomString.py 60
|
||||
n51uxDLu3BnxZ1D00gYKYRcG2jh1Y6uulHgrJ0TK3w5FtWl6wm8U0azNtxw0
|
||||
# ^^^^ the above is 60 characters ^^^^
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Hints</summary>
|
||||
|
||||
- Use `random.choice` to generate a random character
|
||||
- build your own alphabet string
|
||||
- Use `sys.argv` to access the CLI Arguments
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>Solution</summary>
|
||||
|
||||
Take a look at the provided Code Example.
|
||||
|
||||
[Code Example](src/randomString.py)
|
||||
|
||||
</details>
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#!/usr/bin/env python3
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
|
||||
def get_random_string(length):
|
||||
# choose from all lowercase letter
|
||||
letters = string.ascii_lowercase
|
||||
result_str = ''.join(random.choice(letters) for i in range(length))
|
||||
alphabet = string.ascii_lowercase
|
||||
alphabet += string.ascii_uppercase
|
||||
alphabet += "0123456789"
|
||||
result_str = ''.join(random.choice(alphabet) for i in range(length))
|
||||
return result_str
|
||||
|
||||
print(get_random_string(20))
|
||||
print(get_random_string(int(sys.argv[1])))
|
||||
|
|
Loading…
Reference in New Issue