Generate random password | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Generate random password

Write a password generator In python - ask the user how strong they want their password to be. For weak passwords, pick two words from a list. For strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols. The passwords should be random and contain at least a combination 5 lowercase and uppercase, 1 number and 1 symbol. Strong password should also be at least length of 10. It should generate a new password every time the user asks for a new password. Include your run-time code in a main method.

29th Apr 2020, 2:40 PM
Aurore, Ya Ting Tan
Aurore, Ya Ting Tan - avatar
4 Answers
+ 1
Don't be afraid: you doesn't do anything illegal ;) I just inform you, that there's better way to help others... and I understand you want practice (but rather do sololearn challenges: QnA challenges are not encouraged at all, and should be avoided... Anyway and conversely, you've good reflex: code review (exploring and/or debuging others codes) is a great efficient way to learn, practice, and discover new things :) Keep on coding and maintain your curiosity \o/
29th Apr 2020, 4:20 PM
visph
visph - avatar
0
from random import choices, choice, sample,shuffle from string import ascii_letters, digits, punctuation while True: #ask user for type of password question= input('Strong or weak password? Enter strong or weak: ') #list for weak passwords list1= ['banana', 'coconut', 'eclair', 'pineapple', 'alligator', 'caterpillar', 'england', 'flamingo'] if question=='weak': weak= choices(list1, weights= None, k= 2) print(''.join(weak)) break elif question=='strong': letter_len=10 num_len=2 random_symbol=choice(punctuation) random_letters=''.join(choice(ascii_letters) for i in range(letter_len)) random_num=''.join(choice(digits) for i in range(num_len)) strong=random_symbol+random_letters+random_num random_strong=''.join(sample(strong, len(strong))) print(random_strong) break else: print('Invalid option. Enter \'strong\' or \'weak\'') #feel free to comment and make my code better :)
29th Apr 2020, 2:46 PM
Aurore, Ya Ting Tan
Aurore, Ya Ting Tan - avatar
0
Aurore, Ya Ting Tan by giving full code to lazy OPs, you doesn't help them... Rather guide them if they don't have any own code attempt to show, or correct and explain else (if not too much errors... correcting a full not working code is less worth than being exploited for doing homework ;))
29th Apr 2020, 3:50 PM
visph
visph - avatar
0
hi visph, sorry I’m new to this and is a recent learner of python. From what i understood this is the place to post question and discuss answers. I modify and created this question for myself to learn, so i am not sure if my answer is ‘ideal’, thus I post my answer here. I assumed people are here to learn, even from learning how to write proper code from ‘answers’. didn’t think people will just copy answers.. that defeats the purpose of this platform isnt it? Anyhow, so am I suppose to take down my answer first?
29th Apr 2020, 4:09 PM
Aurore, Ya Ting Tan
Aurore, Ya Ting Tan - avatar