#๐Ÿ”’ project due in like 2 hours, need help making 3 functions

452 messages ยท Page 1 of 1 (latest)

spice agate
#

title

winter coveBOT
#

@spice agate

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

unkempt pollen
spice agate
#

No starting from scratch

#

jk yeah

#
'Function 1: Password Generation'
def password_generation():
    passw = input("Please create a password: ")
    errorms = password_verification(passw)
    for errorm in errorms:
        print(errorm)
    if not errorms:
        print("Strong password")

'Function 2: Password Verification'
def password_verification(passw):
    errors = []
    specchars = r"""~`!@#$%^&*()_-+={[}]|\:;"'<,>.?/"""
    passw = input("Please create a password: ")
    if len(passw) < 12:
        errors.append("Not enough chars")
    if not any(char.isupper() for char in passw):
        errors.append("This password needs at least one uppercase letter.")
    if not any(char.islower() for char in passw):
        errors.append("This password needs at least one lowercase letter.")
    if not any(char.isdigit() for char in passw):
        errors.append("This password needs at least one number.")
    if not any(char in specchars for char in passw):
        errors.append("This password needs at least one special character (such as:"+specchars)
    return errors
    
password_verification(passw)

'Function 3: MFA and One time password'```
#

these are the directions for the functions

unkempt pollen
#

The principle of single responsibility applies here. A function designed to assess the strength of a password should have a parameter for that password, not accept it via input within the function. Asking for that input may occur elsewhere.

#

Similarly, the result of that function should not be printed within the function, it should return it.

#

To be then printed elsewhere.

spice agate
#
  1. Password Generation:
    make random secure password of 12 chars, must include uppercase letters, lowercase letters, numbers, and special characters.

  2. Password Verification:
    make a function that checks the strength of a password. The function should ensure that the password meets the criteria above.
    give feedback on password strength (e.g., weak, moderate, strong).

  3. multi factor authentication, (MFA) with OTP: make MFA using a one-time password (OTP) system. make a 6-digit OTP and send it to the user (for simplicity, display it in the console). prompt user to enter the OTP and verify it. make sure the OTP expires after a short duration (e.g., 60 seconds).

#

oh

#

yeah for the first one its actually supposed to generate a password, not ask for input

#

so i guess ill have to change that

unkempt pollen
#

!d secrets

winter coveBOT
#

Added in version 3.6.

Source code: Lib/secrets.py

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets...

unkempt pollen
#

Or, if you don't care about security

#

!d random

winter coveBOT
#

Source code: Lib/random.py

This module implements pseudo-random number generators for various distributions.

For integers, there is uniform selection from a range. For sequences, there is uniform selection of a random element, a function to generate a random permutation of a list in-place, and a function for random sampling without replacement...

spice agate
#

i'd import that, or just use x.random?

unkempt pollen
#

There are a number of tools within those libraries you may avail yourself of.

#

See their documentation for specifics.

#

As to OTP, I'm not sure if you're supposed to implement the algorithm yourself or not.

#

I once had a look at it and it's nontrivial.

spice agate
#

i guess it would be similar to function 1 but its just digits

unkempt pollen
#

!pypi pyotp comes up with a brief search

winter coveBOT
#

Python One Time Password Library

Released on <t:1690501263:D>.

spice agate
#

and then i make it disappear within 60 seconds

unkempt pollen
#

It doesn't need to disappear within 60 seconds, but it does need to expire within 60 seconds.

#

Though if you did want to make it disappear, then that might be something for ANSI control codes.

spice agate
#

yeah i guess i mean expire actually

unkempt pollen
#

It sounds like they might just want you to demonstrate equality testing and the use of a datetime or other similar library.

#

and a while loop

spice agate
#

hmm

unkempt pollen
#

!d datetime

winter coveBOT
#

Source code: Lib/datetime.py

The datetime module supplies classes for manipulating dates and times.

While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation...

unkempt pollen
#

!d time

winter coveBOT
#

This module provides various time-related functions. For related functionality, see also the datetime and calendar modules.

Although this module is always available, not all functions are available on all platforms. Most of the functions defined in this module call platform C library functions with the same name. It may sometimes be helpful to consult the platform documentation, because the semantics of these functions varies among platforms.

An explanation of some terminology and conventions is in order...

unkempt pollen
#

I'm guessing you've covered while loops at this stage.

#

Yes?

spice agate
#

yeah

#

its been a while since ive used python so im trying to refigure things out

unkempt pollen
#

Mm.

spice agate
#

im kinda more familiar with java

#

but they have equivalents kinda so im trying to go off that the best i can i guess

#

and similarities

unkempt pollen
#

If you're comfortable with it, regex may be suitable to aspects of your project, but I wouldn't suggest it unless you're already familiar with it.

#

!d re

winter coveBOT
#
re

Source code: Lib/re/

This module provides regular expression matching operations similar to those found in Perl.

Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). However, Unicode strings and 8-bit strings cannot be mixed: that is, you cannot match a Unicode string with a bytes pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string.

spice agate
#

i dont think i am

#

idk if have the time to look to deep into it since i got less than 2 hours to turn it in

unkempt pollen
#

Do you have any more questions at this stage?

#

The main thing you need to figure out is what the functions you're writing should take in via their parameters and what they're returning.

#

Then you need to figure out how you're then acquiring the information you're feeding to the parameters then what you're doing with the returns.

#

Acquire information, information in, process, information out, display.

spice agate
#

yeah i think i get it but i feel like im just confused for somethings

#

let me try to work on it a bit and see though

unkempt pollen
#

Okiedoke.

spice agate
#

thank you for your help

#

is something like this a start?

#
import random

passw = ""
passw.join(random.choice('abcde') for _ in range(3))
print(passw)```
#

for function 1

#

i got the "passw.join(random~" stuff from online

unkempt pollen
#

You're not actually reassigning passw, there.

#

You might like to look at random.choices.

spice agate
#

ohhh

#

ahhh okay i see

#

i see

#

i looked at it for a bit and looked up random.choices and saw that i'd put it in the print statement
!e ```py
import random

passw = ""
print(passw.join(random.choice('abcde') for _ in range(3)))```

unkempt pollen
#

Are you using the passw variable for anything other than the next line?

#

!d random.choices

winter coveBOT
#

random.choices(population, weights=None, *, cum_weights=None, k=1)```
Return a *k* sized list of elements chosen from the *population* with replacement. If the *population* is empty, raises [`IndexError`](https://docs.python.org/3/library/exceptions.html#IndexError).

If a *weights* sequence is specified, selections are made according to the relative weights. Alternatively, if a *cum\_weights* sequence is given, the selections are made according to the cumulative weights (perhaps computed using [`itertools.accumulate()`](https://docs.python.org/3/library/itertools.html#itertools.accumulate)). For example, the relative weights `[10, 5, 30, 5]` are equivalent to the cumulative weights `[10, 15, 45, 50]`. Internally, the relative weights are converted to cumulative weights before making selections, so supplying the cumulative weights saves work.
spice agate
#

nah just the generated passw

unkempt pollen
#

!e py import random population = ['apples', 'pears', 'oranges'] k = 7 choices = random.choices(population, k=k) print(choices)

spice agate
#

well i guess i might reuse that variable in different functions

winter coveBOT
spice agate
#

!e```py
import random

passw = ""
print(passw.join(random.choice('abcde') for _ in range(3)))```

winter coveBOT
spice agate
#

so if i change it a bit

unkempt pollen
#

Also remembering that your objective is to write a function.

#

What should that function accept in terms of parameters, if any?

#

What is that function returning?

#

I'll often use join like py ''.join(...)

spice agate
#

!e```py
import random

passw = ""
print(passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') for _ in range(12)))```

#

probably not as tight and clean as it could be lol i guess but idk

winter coveBOT
spice agate
#

just gotta add special characters to it now

#

its returning a password

unkempt pollen
#

random.choice and random.choices are two different functions.

spice agate
#

oh right this would be in the function, so i guess it might be different

unkempt pollen
#

One is suited for making a single choice, the other is suited to making multiple at once.

spice agate
#

oh

#

i guess the single choice one

unkempt pollen
#

If that's what you want to go with, that'll do.

spice agate
#

!e ```py
import random

def password_generation():
passw = input()
return passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') for _ in range(12))

password_generation()```

winter coveBOT
# spice agate !e ```py import random def password_generation(): passw = input() retur...

:x: Your 3.12 eval job has completed with return code 1.

:warning: Note: input is not supported by the bot :warning:

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 7, in <module>
003 |     password_generation()
004 |   File "/home/main.py", line 4, in password_generation
005 |     passw = input()
006 |             ^^^^^^^
007 | EOFError: EOF when reading a line
spice agate
#

im kinda lost why doesnt calling the function generate

#

anything

unkempt pollen
#

I feel as though you're panicking a little at this point.

spice agate
#

oh cuz its return

#

is it

#

yeah i suppose a bit lol

unkempt pollen
#

The purpose of the input function is to ask the user for text input. The purpose of str.join is to use a string as glue to join together an iterable of strings.

spice agate
#

or i mean i guess its alright but its gonna hurt my grade if i dont turn this in soon i guess

#

oh

unkempt pollen
#

!e py print('*'.join('abcdefg'))

winter coveBOT
unkempt pollen
#

!e py import string print(string.ascii_lowercase)

winter coveBOT
unkempt pollen
#

!d string

winter coveBOT
spice agate
#
import random

def password_generation():
    passw = input("Enter any key to generate a Secure Password: ")
    print (passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') for _ in range(12)))

password_generation()```
#

how do i add special characters to this again

unkempt pollen
#

Either type them in manually as you've been doing, or use the string library for a preprepared set of them.

#
passw = input("Enter any key to generate a Secure Password: ")```This line doesn't belong within this function.
#

Not do you need to assign a variable to it.

spice agate
#

oh i can just say input

unkempt pollen
#

Nor should you be printing within the function.

#

Principle of single responsibility.

#

Each function should have one task

spice agate
#
import random

def password_generation():
    passw = input("Enter any key to generate a Secure Password: ")
    print (passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890r"""~`!@#$%^&*()_-+={[}]|\:;"'<,>.?/"""') for _ in range(12)))

password_generation()```
unkempt pollen
#

You have three tasks in this function. Asking the user to enter in something, generating the password, and printing the password.

spice agate
#

when i try this it doesnt work though i guess because of the quotes

#

oh

#

i see

unkempt pollen
#

All you want this function to do is return the password.

#

I'll say again. The purpose of str.join is to take an iterable of strings and join them together with the glue that you're giving it.

#

!e py print('*'.join('MASH'))

winter coveBOT
unkempt pollen
#

I'll often use py ''.join(...)

#

The function as written asks the user to press any key to proceed. The input function returns upon enter. You're also assigning a variable to it, one you use in str.join.

#

So if the user typed in some string...

#

!e py user_input = 'blah' print(user_input.join('abc'))

winter coveBOT
unkempt pollen
#

You're going to have a weird password.

spice agate
#

i see

#

yeah i noticed that too in fact typing typing and checking it in the compiler

#

so it should look like this

#
import random


passw = input("Press enter to generate a Secure Password: ")

'''Function 1 Pass Gen'''
def password_generation(passw):
    print (passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890') for _ in range(12)))

password_generation(passw)q```
#

idky the special chars arent displaying right though

unkempt pollen
#

Docstrings' conventional location is within the function directly under the def

spice agate
#

i guess the input could say "enter or a key" since it does that kind of weird password making if an actual key other than a blank one is entered like u said

#

oh

#

so i should move it under the def

#

yeah makes sense, i think i do see it a lot like that

#

okay now the special chars

unkempt pollen
spice agate
#

idky i had it in a diff code i was doing yesterday but now its like i cant get it

#

no i think i get it quite well now

unkempt pollen
#

passw.join

#

def password_generation(passw):

spice agate
#

i see that join combined with random makes a scrambled new password

unkempt pollen
#

password_generation(passw)

#

passw = input("Press enter to generate a Secure Password: ")

spice agate
#

random.choices

#

wait im confused

#

is that how it should be

#

ohhh nvm i get it

#

the order

unkempt pollen
#

For this project, you can use either random.choices or random.choice, but they way you'd use them would be slightly different, depending.

spice agate
#

idky this isnt running with the special keys ughhhhhh

#

i just decided to use .choice

unkempt pollen
#

Because you'd need to include the special characters in your population string.

#

The pool from which you are choosing.

#

You've got lowercase and uppercase and digit characters.

#

But no special characters.

spice agate
#

~`!@#$%^&*()_-+={[}]|:;"'<,>.?/

#

this one givs me an error it seemes

#

when i copy paste it

unkempt pollen
#

Oh, I get you.

#

Well, yes, you can either escape certain characters with a backslash, or you can use the string library, as above suggested.

#

!e py print('~`!@#$%^&*()_-+={[}]|:;"\'<,>.?/')

winter coveBOT
spice agate
#

ohhh right the backslash

#

i think one of the people helping me yesterday said to use that too iirc

#

thank you so much man

#

well 39 minutes left

#

lets see if i can do functions 2 and 3 in time

#

hopefully

#

3 seems kinda easier cuz i can just do the same thing for 1

#

but just digits

unkempt pollen
#

It's doable.

#

You've just got to keep your head.

#

If you periodically post works in progress as you go, I can comment.

#

I'll make an effort to communicate effectively.

spice agate
#

oh alright sorry i meant to post what i got

unkempt pollen
#

Anything a function needs to run should go in via a parameter except for constants. Any information that function is generating should be returned, not printed. A function can display information, but only if that is its specific and sole purpose.

spice agate
#
import random
'Function 1L Password Generator'
def password_generation(passw):
    print ("Your Secure Password is: "+passw.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|:;"\'<,>.?/') for _ in range(12)))


passw = input("Press enter [or a key] to generate a Secure Password.\nEntering a key other than 'enter' will add it in the password's generator algorithm: ")
password_generation(passw)```
#

thats 1, pretty much done i guess

#

that L shouldnt be there, mistake

unkempt pollen
#

There are problems with this, but let's move on to the next function.

#

It will at least do a thing.

spice agate
#

oh there is? aww

#

ill do 3 then 2 then we can come back to 1 then

#

well

unkempt pollen
# spice agate oh there is? aww

It will achieve a result that may well satisfy the user, but from an operational and structural perspective, there are some issues.

spice agate
#
'Function 3: Multi-Factor Authentication with One-Time-Password'
def multifactorauthen_otp(passw):
    print ("Your One-Time-Password is: "+passw.join(random.choice('1234567890') for _ in range(6)))

otpassw = input("\nPress ONLY enter to generate a 6 digit pin: ")
multifactorauthen_otp(otpassw)
#

they're all on one thing but ill just post 3 so it doesnt look too cluttered and confusing

unkempt pollen
#
def func():
   """Docstrings go here."""
   ...```
#

Conventionally written with three double quotes.

spice agate
#

docstrings like comments?

#

oh

unkempt pollen
#

No, docstrings like documentation.

#

You're using a string as a comment.

spice agate
#

oh yeah i mean like that

#

oh

#

should i move it or just change the quotes to """

#

or do both

unkempt pollen
#

Which you can do with #

spice agate
#

ohhhhhhhhhh right

#

i forgot i could do comments with that

#

java its different so ive forgotten

unkempt pollen
#
# This is the so and so function.
def func():
    ...```If you're going to do that sort of thing.
spice agate
#

its like /* */ in java or something

#

ohhh i see

#

and //

unkempt pollen
#

This function doesn't need a parameter.

#

Or at least not as you've written it.

#

You're assigning otpassw to the user input. You needn't.

#

Same as like with above.

spice agate
#

oh ok

unkempt pollen
#

Look at the requirements for function 3.

spice agate
#

wait but the user is supposed to interact with it

#

so them putting the input is just like a prompt thing for them to generate it

#

otherwise yeah i'd just display it

#

also for function 3 the user does have to verify the otp

#

so ill have to whoa Goku

#

but yeah ill have to still add a prompt in the function

raven dagger
#

why are you hardcoding every single key

#

like PLEASE use ord and chr ๐Ÿ˜ญ

spice agate
#

ord and chr??

unkempt pollen
#

Please don't?

spice agate
#

dont what use ord and chr or add an input prompt

unkempt pollen
#

I've already suggested the use of the string library.

#

But here we are.

spice agate
#

id look into it but i dont have as much time

unkempt pollen
#

Anyway, what have you got letft?

#

You've got to use some kind of time or datetime library, I think.

spice agate
#

now i gotta add a prompt to verify it first

unkempt pollen
#

That's one part, yes.

spice agate
#
#Function 3: Multi-Factor Authentication with One-Time-Password
def multifactorauthen_otp(passw):
    print ("Your One-Time-Password is: "+passw.join(random.choice('1234567890') for _ in range(6)))
    verifyp = input("Verify the OTP: ")
    if verifyp = passw
        print("Your OTP has been verified").```
#

13 mins left

#

might be ggs

#

still gonna try though

#

is that good

unkempt pollen
#

def multifactorauthen_otp(passw):
passw.join

#

This is something you keep doing.

spice agate
#

oh should i not?

#

i guess i would rather have it so entering any key would make that fixed number generate

unkempt pollen
#

That's why I was going on about str.join before.

spice agate
#

i see

unkempt pollen
#

The glue string.

#

All you need is a zero length string./

spice agate
#

yeah i was tryna work to finish it, sorry if it seemed like i was being hard headed and ignoring u on that

#

oh

unkempt pollen
#

== for equality checking

spice agate
#

right right

unkempt pollen
#

= is for assignment

raven dagger
#

don't forget colon :

spice agate
#

yeah true

#

so str.join instead of passw.join?

unkempt pollen
#

''.join(...)

spice agate
#

wait

unkempt pollen
#

otherwise it'd be str.join('', ...)

spice agate
#

oh

#

right

#

ohhhhhhhhhhhhhhhhhhhhhh

unkempt pollen
spice agate
#

yeah cuz i legit fully read what u said multiple times

#

but it just didnt really hit me until now LMFAOOO

#

wow

unkempt pollen
#

Come on. Time-constraints.

#

The time library is probably simpler, but datetime is probably more idiomatically appropriate.

spice agate
#

i saw what the code was for that but i forgot

#

lemme look for it again

unkempt pollen
#

!d datetime

winter coveBOT
#

Source code: Lib/datetime.py

The datetime module supplies classes for manipulating dates and times.

While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation...

spice agate
#

oh right

#

when i looked it up before, i also saw an "expire" code

#

i would use that?

unkempt pollen
#

I don't see that listed in the documentation.

spice agate
#

from _datetime import

#

waittt

#

oh wait nvm

#

i scrolled in the doc a bit

#

so i guess i could use this

#
duration = timedelta(seconds=11235813)```
unkempt pollen
#

!e py import datetime now = datetime.datetime.now() print(now)

winter coveBOT
unkempt pollen
#

Timedelta. Mhm.

#

Also, datetime objects are logically comparable.

#

== > < etc

spice agate
#

hmm so whats better

#

import datetime or

#

from datetime import timedelta

#

so i could logically compare it to seconds?

#

welp thats a bunch of points off

#

arghhhhhhhh i shouldve came back to this earlier

unkempt pollen
#

Either is fine.

spice agate
#

oh well

#

i see

#

i guess ill use yours

unkempt pollen
#

Deadline expired?

spice agate
#

yeah its probably late now but oh well ill just still finish it

#

so when i import

#

it'd look like this?

unkempt pollen
spice agate
#

import random, datetime

unkempt pollen
#

YOu can do that, yes.

spice agate
#

LOL yeah but its like my body insists i do things close to the last minute

unkempt pollen
#

Would you like me to stick around until you finish? Otherwise I'll just check back in occasionally.

#

Given you'e post-deadline.

spice agate
#

otpexpire = timedelta(seconds=60)

#

uhhh yeahhh i think once i get the time thing

unkempt pollen
#

That's not the right syntax.

spice agate
#

oh lemme fix it

#

ill show u function 2 and if u think its good then thats it, theres only like 1 other thing i'd have to do

unkempt pollen
#

Mhm

spice agate
#

so this means ill expire in 60 secs?

#

itll

unkempt pollen
#

Shall I notify an undertaker?

spice agate
#

lol

unkempt pollen
#

datatime.datetime instances can have datetime.timedelta instances added to them.

#

datetime.datetime instances are logically comparable to one another.

#

> < == etc

spice agate
#

LOL ohhhhh

#

so would u write that like

#

otpexpire == datetime.datetime.now(seconds = 60)?

#

orrrrrrr uhhh

unkempt pollen
#

!d datetime.datetime.now

winter coveBOT
#

classmethod datetime.now(tz=None)```
Return the current local date and time.

If optional argument *tz* is `None` or not specified, this is like [`today()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.today), but, if possible, supplies more precision than can be gotten from going through a [`time.time()`](https://docs.python.org/3/library/time.html#time.time) timestamp (for example, this may be possible on platforms supplying the C `gettimeofday()` function).

If *tz* is not `None`, it must be an instance of a [`tzinfo`](https://docs.python.org/3/library/datetime.html#datetime.tzinfo) subclass, and the current date and time are converted to *tz*โ€™s time zone...
spice agate
#

thanks

spice agate
#

oh im dumb id just use that

unkempt pollen
#

!e py import datetime now = datetime.datetime.now() then = now + datetime.timedelta(seconds=30) print(now) print(then) print(then > now)

winter coveBOT
unkempt pollen
#

This isn't a suggestion for what you'd include in your code.

spice agate
#

ok i think i understand that a lot more now

unkempt pollen
spice agate
#

oh

unkempt pollen
#

A demonstration to be understood, not copied, is what I mean.

#

You may find that through understanding you want to do some of this.

#

You may not. You may do something different.

spice agate
#

ohhhhh i seeeee

#

wait so is now its own thing

unkempt pollen
#

now is just a variable name I've chosen

#

datetime.datetime.now is a thing in the library

spice agate
#

or would i make the otp variable equivalent to now

#

oh

unkempt pollen
#

datetime.datetime.now() is a datetime.datetime instance that represents the time at the call.

spice agate
#

ohhh

#

h

unkempt pollen
#

You may want to call that more than once.

spice agate
#

okay so i got this now

#
#Function 3: Multi-Factor Authentication with One-Time-Password
import random, datetime

def multifactorauthen_otp(passw):
    print ("Your One-Time-Password is: "+''.join(random.choice('1234567890') for _ in range(6)))
    verifyp = input("\nVerify the OTP: ")
    if verifyp == passw:
        print("Your OTP has been verified.")
    else:
        print("Your OTP could not be verified.")
        
    passw = datetime.datetime(passw)
    expireotp = passw + datetime.timedelta(seconds=20)
    if expireotp>passw:
        print("Your OTP has expired.")
        ```
#

i know it got some error

#

s

unkempt pollen
#

What's going on with the parameter, there?

#

You're reusing the variable.

#

Also, maybe a while loop.

spice agate
#

oh i thought i could use the otp variable for the time variable

#

guess not

#

ahhhh true

unkempt pollen
#

What are you comparing the user input against?

#

What do you need to compare it against?

spice agate
#

yeah true

#

ohhh its wrong cuz it wasnt datetime.datetime.now

unkempt pollen
#

Descriptive naming conventions.

#

Good practice.

#

Have variables that are descriptive of the things they are assigned to.

spice agate
#

yeah thats why i thought to use "passw", as it would be the otp at that time before expiring

unkempt pollen
#

Is it a password?

spice agate
#

i guess i could just make a new variable saying "otp" though

#

no its the variable for the current time comparison

unkempt pollen
#

Is it the otp?

#

Mm.

unkempt pollen
spice agate
#

yeah

#
import random, datetime
#Function 3: Multi-Factor Authentication with One-Time-Password
def multifactorauthen_otp(passw):
    print ("Your One-Time-Password is: "+''.join(random.choice('1234567890') for _ in range(6)))
    verifyp = input("\nVerify the OTP: ")
    if verifyp == passw:
        print("Your OTP has been verified.")
    else:
        print("Your OTP could not be verified.")
        
    otpassw = datetime.datetime.now()
    expireotp = otpassw + datetime.timedelta(seconds=20)
    if expireotp>otpassw:
        print("Your OTP has expired.")
        
#

this runs

#

althoughhhhh idky with the verification part

#

even if u put like the wrong number it still says its verified

#

and if u put the right one it says it isnt

#

i tried using if not which does better but i think that one isnt 100% accurate when i was running it for tests multiple times

unkempt pollen
#

You have two checks that you need to perform. What are they?

spice agate
#

uhhh enter the otp and verify it?

unkempt pollen
#

Entering the otp isn't a check.

spice agate
#

oh

#

verify OTP and otp expire?

unkempt pollen
#

Verifying it for correctness is one.

#

Yes.

#

Are you comparing it for correctness?

spice agate
#

yes

#

oh should i remove the if statement

#

wait no

#

hm

unkempt pollen
#

Where are you keeping the otp code?

#

Where are you then using that to compare against?

spice agate
#

ohhhh ur right

#

passw in there doesnt have anything that really makes it equal i think

#

hmmmm

#

wait huh

#

wait the otp would be in passw

unkempt pollen
#

Is it?

spice agate
#

so verifyp would be the comparison to passw the otp code

#

i think so

unkempt pollen
#

Where are you creating the code?

#

How are you storing it?

spice agate
#
passw = input("Press any key to generate a Secure Password: ")
password_generation(passw)

otpassw = input("\nPress any key to generate a 6 digit pin: ")
multifactorauthen_otp(passw)
#

cuz thats the call

unkempt pollen
#

Is it late for you?

#

Are you tired?

spice agate
#

tbh kinda but i gotta finish this

#

oh do u have to go soon

unkempt pollen
#

In ten or so minutes, yes. But also, you don't appear to be thinking very clearly.

#

Usually this is a result of fatigue.

spice agate
#

i've been up nearly all day to tbh so shoot yeah probably

#

since yesterday

unkempt pollen
#

I am suggesting that there may be little point for you to continue at this point. Pushing through may be a valid option if you're making progress.

spice agate
#

i mean i feel like im so close to finishing though

unkempt pollen
#

Rest may be ultimately more enabling to future productivity.

#

Whereas putting off rest isn't netting you good result and will rob future productivity.

spice agate
#

what did i do that was wrong with the code :' (

#

that makes u say that

unkempt pollen
#

You do not need to assign a variable to input unless you're going to use what the user types in.

#

If you do use what they typed in, make sure you need to.

#

If you generate the otp code, you will need to have some way to refer to it.

#

As it stands, you print it but do not store it in your code.

spice agate
#

ohhhh

#

i see what u mean

#

i have to make it equal something

#

i was thinking it would work from the call but i forgot its generated

#

have to actually make it

unkempt pollen
#

You will want to assign a variable to the otp code so that you can then print it and also compare things against it later.

spice agate
#

yeahhh

unkempt pollen
#

It's like cramming the night before an exam into the night. You get tired, you're not absorbing information very much, then by the time the exam swings around, you've also killed your recall for the things you do know, because you're tired.

#

Long term, rest is a better strategy.

#

To get over a deadline, yeah, you can push a bit.

#

So long as there is rest afterward.

#

But push push push all the time is not a productive strategy.

#

You get more and better work done with rest, long term.

#

Maintain thyself.

spice agate
#

Hmmmm

unkempt pollen
#

I'm going, now.

#

Good luck.

spice agate
#

thanks a lot man

#

i learned a lot from you

#

now i just need to check function 2 i guess

#
import random, datetime
#Function 1: Password Generator'
def password_generation(passw):
    print ("Your Secure Password is: "+''.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|:;"\'<,>.?/') for _ in range(12)))


#Function 3: Multi-Factor Authentication with One-Time-Password
def multifactorauthen_otp(passw):
    passw = ''.join(random.choice('1234567890') for _ in range(6))
    print ("Your One-Time-Password is: "+passw)
    verifyp = input("\nVerify the OTP: ")
    if verifyp == passw:
        print("Your OTP has been verified.")
    else:
        print("Your OTP could not be verified.")
        
    otpassw = datetime.datetime.now()
    expireotp = otpassw + datetime.timedelta(seconds=20)
    if expireotp>otpassw:
        print("Your OTP has expired.")
        





passw = input("Press any key to generate a Secure Password: ")
password_generation(passw)

otpassw = input("\nPress any key to generate a 6 digit pin: ")
multifactorauthen_otp(passw) ```
spice agate
#
import random, datetime, time
#Function 1: Password Generator
def password_generation(passw):
    print ("Your Secure Password is: "+''.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~`!@#$%^&*()_-+={[}]|:;"\'<,>.?/') for _ in range(12)))

#Function 2: Password Verification
def password_verification(passw):
    if(len(passw)<8):
        print("Weak password. Please use more characters.")
    elif(len(passw)>=12):
        print("Moderate password. A bit more characters will make this a strong password.")
    elif(len(passw)>=16):
        print("Strong password")

#Function 3: Multi-Factor Authentication with One-Time-Password
def multifactorauthen_otp(passw):
    passw = ''.join(random.choice('1234567890') for _ in range(6))
    print ("Your One-Time-Password is: "+passw)
    verifyp = input("\nVerify the OTP: ")
    if verifyp == passw:
        print("Your OTP has been verified.")
    else:
        print("Your OTP could not be verified.")
        
    otpassw = datetime.datetime.now()
    expireotp = otpassw + datetime.timedelta(seconds=20)
    if expireotp>otpassw:
        print("Your OTP will expire in 20 seconds.")
        time.sleep(20)
        print("Your OTP has expired.")
        





spassw = input("Press any key to generate a Secure Password: ")
password_generation(spassw)

passwv = input("Press any key to input a password, and it's strength will be tested: ")
password_verification(passwv)

otpassw = input("\nPress any key to generate a 6 digit pin: ")
winter coveBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.