Пример #1
0
 def test_save_creds(self):
     flickr = MockFlickrApi()
     creds_store = MockCredentialStore()
     authenticate(True, flickr, MockAuthHandler, creds_store,
             MockAuthUi('the code'))
     self.assertEqual(auth_instance.saved_to,
             creds_store.credentials_path())
def authenticate_client():
    req=request.json
    print("i am here")
    server=req['server']
    username=req['userName']
    password=req['password']
    database=req['database']
    authenticate(username,password,database)
    return jsonify({'result':'success'})
Пример #3
0
def login(username, maxattempts=1):
    """str, int(optional). Prompt for password and tests if correct or not.
    Args:
        username(str): Arg of username as a string.
        maxattempts(int, optional): attmepts to enter correct password as int.
    Returns:
        Something.
    Example:
        >>> import task_02
        task_02.login('mike', 4)
    Please enter your password:
    Incorrect username or password. You have 3 attempts left.
    Please enter your password:
    Incorrect username or password. You have 2 attempts left.
    Please enter your password:
    Incorrect username or password. You have 1 attempts left.
    Please enter your password:
    Incorrect username or password. You have 0 attempts left.
    False>>>
    """
    authenticated = False
    attleft = 'Incorrect username or password. You have {} attempts left.'

    while not authenticated and maxattempts != 0:
        passinput = getpass.getpass()
        print passinput
        authenticated = authentication.authenticate(username, passinput)
        if authenticated is True:
            return authenticated
        elif not authenticated and maxattempts != 0:
            maxattempts -= 1
            print attleft.format(maxattempts)
    return authenticated
Пример #4
0
def login(username, maxattempts=3):
    """Login module.

    Args:
        username (str): Name of user.
        maxattempts (int, optional): Max number of attempts, defaults to 3.

    Returns:
        bool: Whether login is successful or not (True/False).

    Examples:
        >>> task_02.login('violet', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        >>> task_02.login('mike', )
        Please enter your password:
        True
    """
    auth = False
    wrong = 'Incorrect username or password. You have {0} attempts left.'
    while auth is False and maxattempts > 0:
        password = getpass.getpass('Please enter your password: ')
        auth = authentication.authenticate(username, password)
        if auth is False:
            maxattempts -= 1
            print wrong.format(maxattempts)
    return auth
Пример #5
0
def login(username, maxattempts=3):
    """Input username and password practice.
    Arguments:
        username (str): username from list of approved users
        maxattampts (int): defaults to 3 unless otherwise input
    Returns:
        prompt to enter password, under variable stringput. If
        entered incorrectly returns failattempt variable and
        displays number of remaining tries.
    Examples:
        login('augustus')
        >>>Please enter your password:
        If correct:
            True
        If incorrect:
            Incorrect username or password.You have 2 attempts left.
    """
    authenticated = False
    failattempt = 'Incorrect username or password.You have {} attempts left.'

    attempt_num = 0
    while not authenticated and attempt_num < maxattempts:
        password = getpass.getpass('Please enter your password:')
        authenticated = authentication.authenticate(username, password)
        if not authenticated:
            attempt_num += 1
            print failattempt.format(maxattempts - attempt_num)

    return authenticated
Пример #6
0
def flickr_to_go(dest, savecreds, key, secret, output=sys.stdout):
    start_time = time.time()
    timestamp_path = os.path.join(dest, 'timestamp')
    flickr_api.set_keys(api_key=key, api_secret=secret)
    file_store = FileStore(dest)
    user = authenticate(savecreds, flickr_api, auth.AuthHandler, file_store)
    if not user:
        return False

    err_path = os.path.join(dest, "errors.txt")
    with open(err_path, 'w') as errfile:
        errors = ErrorHandler(errfile)
        downloader = FlickrApiDownloader(file_store, errors)
        photos = photolist.download(downloader, flickr)
        if photos is None:
            output.write("Photo list download failed. Can't continue.\n")
            return False
        containers.download(downloader, flickr)
        last_time = read_timestamp(timestamp_path)
        if last_time is None:
            recently_updated = []
        else:
            recently_updated = photolist.fetch_recently_updated(last_time,
                downloader, flickr) or []
        photo.download(photos, recently_updated, downloader, flickr)

        if errors.has_errors():
            print("Some requests failed.")
            print("Errors are logged to %s" % err_path)
            return False

    with open(timestamp_path, 'w') as f:
        f.write(str(int(round(start_time))))
    return True
def login(username, maxattempts=3):
    """ 1.  username (str): A string representing
    the username of the userattempting to log in
    2.  maxattempts (int, optional):
    An integer represent the maximum number of prompted attempts
    before the function returns False. Defaults to ``3``"""
    authenticate = False
    password = getpass.getpass(prompt='Password: '******'Please enter your password: ')
        authentication.authenticate(username, password, maxattempts)
        if password >= maxattempts:
            return False
        else:
            return True
Пример #8
0
def main():
    parser = get_arg_parser()
    print(DESCRIPTION + "\n")

    args = None
    authedOnce = False
    i = 0
    while True:
        i += 1
        args = get_user_commands(parser, args)

        if authedOnce:
            args['auth'] = False

        if args['auth']:
            print('Client: authenticating server...')
            args['key'] = authenticate(args)
            if args['key'] == False:
                print('authentication failed, closing connection')
                exit(1)
            else:
                print('successfully authenticated :D')
                authedOnce = True
                continue

        args['auth'] = False
        # import time
        # time.sleep(5)
        resp = exec_function(args)
Пример #9
0
def login(username, maxattempts=3):
    """A function to log a user in.

    Args:
        username (str), required: User's login name.
        maxattempts (int): Maximum number of login tries. Default = 3.

    Returns:
        bool: Whether a user has been successfully authenticated.

    Examples:
        >>> task_02.login('mike', 2)
        Please enter your password:
        Incorrect username of password. You have 1 attempts left.
        Please enter your password:
        Incorrect username of password. You have 0 attempts left.
        False

        >>> task_02.login('veruca', 2)
        Please enter your password:
        True
    """
    authenticated = False
    attempted = 0
    errormsg = 'Incorrect username of password. You have {0} attempts left.'
    while attempted < maxattempts and authenticated is False:
        password = getpass.getpass('Please enter your password:')
        authenticated = authentication.authenticate(username, password)
        attempted += 1
        if authenticated is False:
            print errormsg.format(maxattempts - attempted)
        else:
            return True
    return False
Пример #10
0
    def handle(self):

        request = self.request.recv(1024)
        authenticated_request=authenticate(directory_server_key, request)
        #If its a read request the server returns the location of the file
        #Location is server address. This could be easly expanded upon.
        if("READ" in authenticated_request):
            server_address=find_file(directory_server.directory_of_files,authenticated_request)
            if(not server_address == None):
                formated_server_address="{}\n{}".format(server_address[0],server_address[1])
                print formated_server_address
                self.request.send(formated_server_address)
            else:
                #no file in the server
                self.request.send("File Does Not Exist")

        #Checks if the file exists. If it doesnt It finds a suitable file_server else return the file server location
        #
        elif("WRITE" in authenticated_request):
            #request in form ADD\nfile_location\nfile_name
            server_address=find_file(directory_server.directory_of_files,authenticated_request)
            if(server_address==None):
                server_address= find_suitable_server(primary_file_port)
            directory_server.directory_of_files=add_file(directory_server.directory_of_files,authenticated_request,server_address)
            formated_server_address="{}\n{}".format(server_address[0],server_address[1])
            print formated_server_address
            self.request.send(formated_server_address)
Пример #11
0
def login(username, maxattempts=3):
    """Lets the user in if the password is correct.

    Args:
        username (str): user inputs username
        maxattempts (int, optional): max number of allowed attempts

    Returns:
        Returns a boolean value of true or false based on if U/P are correct.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

    """
    attempt = 0
    failiure = 'Incorrect username/password. You have {} attempts left!'
    authenticated = False
    while not authenticated and attempt < maxattempts:
        enter = getpass.getpass('Please enter password')
        if authentication.authenticate(username, enter) is True:
            authenticated = True
        else:
            attempt += 1
            print failiure.format(maxattempts - attempt)
    return authenticated
Пример #12
0
def login(username, maxattempts=3):
    """To verify one's account ID and password.

    Args:
    username(str): input username.
    maxattempts(int): maximum attempts allowed.

    Returns:
    Bool: to return whether if someone entered the matching value, in boolen.

    Examples:

        >>>task_02.login('mike', 2)
        'Please enter your password:
         Incorrect username of password. You have 1 attempts left.
         Please enter your password:
         Incorrect username of password. You have 0 attempts left.
         False'
    """
    authenticated = False
    attempts = 0
    fail_message = 'Incorrect username or password. You have {0} attempts left.'
    while attempts < maxattempts and authenticated is False:
        password = getpass.getpass('Please enter your password: ')
        info = authentication.authenticate(username, password)
        attempts += 1
        if info is False:
            print fail_message.format(maxattempts - attempts)
        else:
            return True
    return authenticated
Пример #13
0
def login(username, maxattempts=3):
    """This function simulates user login authentication.

    This function makes use of the getpass and authenticate modules to
    simulate user login authentication.

    Args:
        username (str): A username as defined in the assignment.
        maxattempts (int): Maximum number of allowed login attempts.

    Returns:
        True or False

    Example:
        >>> login('mike', 5)
        Enter Password:
        Incorrect username or password. You have 4 attempts left.
        Enter Password:
        Incorrect username or password. You have 3 attempts left.
        Enter Password:
        Incorrect username or password. You have 2 attempts left.
        Enter Password:
        True
    """
    authenticated = False
    warning = 'Incorrect username or password. You have {} attempts left.'
    while not authenticated and (maxattempts > 0):
        mypass = getpass.getpass('Enter Password: ')
        if authentication.authenticate(username, mypass) is True:
            authenticated = True
        else:
            maxattempts -= 1
            if maxattempts != 0:
                print warning.format(maxattempts)
    return authenticated
Пример #14
0
    def login(self):
        retry = 0
        while True:
            try:
                if retry >= LOGIN_RETRY_MAX:
                    print "Permission denied (login attemps have been reported)."
                    exit(1)

                username = raw_input('Username: '******'Password: '******'Ctrl-C -- exit!\nAborted'
                exit(1)
            except EOFError:
                print "Permission denied, please try again."
def login(username, maxattempts=3):

    count = False
    attempts = 1

    start = 'Please Enter the password: '******'Password Incorrect. {0} attempts remaining. '

    while attempts <= maxattempts:

        passauth = getpass.getpass(start)

        output = authentication.authenticate(username, passauth)

        if output:

            count = True
            break

        else:

            print wrongpassword.format(maxattempts - attempts)
            attempts += 1

    return count
Пример #16
0
def list_photos(directory, username, password, size, download_videos, force_size, \
    smtp_username, smtp_password, notification_email):
    """Prints out file path of photos that will be downloaded"""

    if not notification_email:
        notification_email = smtp_username

    icloud = authenticate(username, password, smtp_username, smtp_password,
                          notification_email)
    all_photos = icloud.photos.all

    directory = os.path.normpath(directory)

    for photo in all_photos:
        for _ in range(MAX_RETRIES):
            try:
                if not download_videos \
                    and not photo.filename.lower().endswith(('.png', '.jpg', '.jpeg')):
                    continue

                created_date = photo.created
                date_path = '{:%Y/%m/%d}'.format(created_date)
                download_dir = os.path.join(directory, date_path)

                # Strip any non-ascii characters.
                filename = photo.filename.encode('utf-8') \
                    .decode('ascii', 'ignore').replace('.', '-%s.' % size)

                download_path = os.path.join(download_dir, filename)
                print(download_path)

                break

            except (requests.exceptions.ConnectionError, socket.timeout):
                time.sleep(WAIT_SECONDS)
def login(username, maxattempts=3):
    """A login page.

    Agrs:
         The username of the user attempting to log in.
         The maximum number of prompted attempts.

    Returns:
        Return True if the user has successfully authenticated
        False if they exceed that maximum number of failed attempts.


    """
    authenticated = False
    counter = 0
    message = "Incorrect username or password. You have {} attempts left"
    while counter < maxattempts and not authenticated:
        password = getpass.getpass("Please enter your password?")
        usrauth = authentication.authenticate(username, password)
        if usrauth is not False:
            authenticated = True
        else:
            counter += 1
            print message.format(maxattempts - counter)
    return authenticated
Пример #18
0
def login(username, maxattempts=3):
    ''' This function takes only 2 functions. Login and password
    Args:
        username(string): This will be a username for login
        maxattempts(optional int): This will include number of login attempts
        till user gets locked
    Returns:
        positive(boolean)
        True or  false value if password matches or not.
    Examples:
        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        True
    '''
    positive = False
    attempt = 1

    login_message = 'Please enter your password: '******'Incorrect username or password. You have {0} attempts left'

    while attempt <= maxattempts:
        passauthen = getpass.getpass(login_message)
        promptoutupt = authentication.authenticate(username, passauthen)
        if promptoutupt:
            positive = True
            break
        else:
            print error_message.format(maxattempts - attempt)
            attempt += 1
    return positive
def login(username, maxattempts=3):
    """ This function authenticates users using the getpass and authenticate
    modules.

    Args:
        username (str): A username.
        maxattempts (int): Max number of allowed attemps.  Default = 3.

    Returns:
        True or False.

    """
    authenticated = False
    attempt = 0
    warning = 'Incorrect username or password.  You have {} attempts left.'

    while not authenticated and attempt < maxattempts:
        mypass = getpass.getpass('Please enter your password:')

        if authentication.authenticate(username, mypass) is True:
            authenticated = True

        else:
            attempt += 1
            print warning.format(maxattempts - attempt)
    return authenticated
def login(username, maxattempts=3):
    """ This function authenticates users using the getpass and authenticate
    modules.

    Args:
        username (str): A username.
        maxattempts (int): Max number of allowed attemps.  Default = 3.

    Returns:
        True or False.

    """
    authenticated = False
    attempt = 0
    warning = 'Incorrect username or password.  You have {} attempts left.'

    while not authenticated and attempt < maxattempts:
        mypass = getpass.getpass('Please enter your password:')

        if authentication.authenticate(username, mypass) is True:
            authenticated = True

        else:
            attempt += 1
            print warning.format(maxattempts - attempt)
    return authenticated
Пример #21
0
def getList():
    json_file_name = 'hip-host-262902-bbbb44360c3f.json'
    credential = authentication.authenticate(json_file_name)
    gc = gspread.authorize(credential)
    wks = gc.open("domainTest").sheet1

    values_list = wks.col_values(1)
    return values_list
Пример #22
0
def main():    
    # Require user to login or signup
    clearScreen()
    while(not authentication.currentUser):
      if(authentication.authenticate()):
        clearScreen()
        print('Welcome,', authentication.currentUser)
    mainMenu()
Пример #23
0
 def test_http_error(self):
     global to_raise
     flickr = MockFlickrApi()
     to_raise = urllib2.HTTPError('http://example.com/auth/', 401,
             'nope', None, None)
     result = authenticate(False, flickr, MockAuthHandler,
             MockCredentialStore(), MockAuthUi('c', True))
     self.assertIs(result, None)
Пример #24
0
 def test_success(self):
     flickr = MockFlickrApi()
     result = authenticate(False, flickr, MockAuthHandler,
             MockCredentialStore(), MockAuthUi('the code'))
     self.assertIs(result, flickr.test.login())
     self.assertEqual(auth_instance.callback, 'oob')
     self.assertEqual(auth_instance.perms, 'read')
     self.assertEqual(auth_instance.verifier, 'the code')
     self.assertEqual(flickr.auth_handler, auth_instance)
Пример #25
0
def list_notes():
    user = authenticate(request)

    if user is None:
        response.status = 401
        return {'error': 'Authentication credentials not valid.'}

    notes = notes_schema.dumps(Note.select().where(Note.owner == user.id))
    return notes.data
Пример #26
0
def login_user(args):
    user = authenticate(args['username'], args['password'])
    if user is None:
        return {'login': False, 'message': _('Bad username or password')}
    if not user.active:
        return {
            'login': False,
            'message': _('Your account is pending for activation')
        }
    access_token = create_access_token(identity=user)
    return {'login': True, 'access_token': access_token}
Пример #27
0
    def run(self):
        """ main control loop """
        print("%s starts" % (self.getName(), ))
        self.driver = webdriver.Chrome()
        self.driver.get(
            'https://dossieretudiant.polymtl.ca/WebEtudiant7/poly.html')
        assert ("Dossier") in self.driver.title
        print("Webpage loading: Successfull")

        assert ("Dossier") in self.driver.title
        authenticate(self.driver)
        print("Login: Successfull")
        is_menu_loaded(self.driver)
        print("Class Modifications Page: Successfull")

        registered_in_class(self.driver, self.class_list)
        classes_registered_count = sum(value.is_registered == True
                                       for value in self.class_list)
        classes_to_register = [
            school_class for school_class in self.class_list
            if school_class.is_registered == False
        ]

        count = 0
        while not self._stopevent.isSet():
            for school_class in classes_to_register:
                if assign_class(self.driver, classes_registered_count + 1,
                                school_class.class_number):
                    if not is_connected(self.driver):
                        break
                    is_menu_loaded(self.driver)
                    classes_registered_count += 1
                    registered_in_class(self.driver, self.class_list)
                    classes_to_register.remove(school_class)
                    playsound('C:/thereminDemo.wav')
                time.sleep(random.randrange(3, 6, 1))
            count += 1
            print("loop %d" % (count, ))
            self._stopevent.wait(self._sleepperiod)

        print("%s ends" % (self.getName(), ))
Пример #28
0
def start_streaming(credential, target_table, tracks=None, locations=None):
    assert (tracks is not None) or (locations is not None)
    listener = PgListener()
    listener.reset_counter()
    listener.set_target_table(target_table)
    listener.set_connection(get_pg_connection())
    auth = authenticate(credential)
    stream = Stream(auth, listener)
    if tracks is not None:
        stream.filter(track=tracks)
    elif locations is not None:
        stream.filter(locations=locations)
Пример #29
0
def upload(img):
    # authenticate first
    client = authenticate()
    config = {'album': album_id}

    if client is not None:
        img_path = os.path.join('', img)
        if os.path.exists(img_path):
            resp = client.upload_from_path(img_path, config=config, anon=False)
        else:
            resp = client.upload_from_url(img_path, config=config, anon=False)
    print("Upload finished. \n\t id : {0:<10}\n\tlink : {1:<10}".format(
        resp['id'], resp['link']))
def login(username, maxattempts=3):
    valid = False
    current_attempts = 0
    false = "Incorrect username or password. You have {} attempts left!"
    while current_attempts < maxattempts:
        password = getpass.getpass()
        valid = authentication.authenticate(username, password)
        if valid == True:
            return valid
        else:
            current_attempts += 1
            print false.format(maxattempts - current_attempts)
    return valid
Пример #31
0
def check_authentication():
     username = request.args.get("username")
     password_hash = request.args.get("password_hash")
     result = authentication.authenticate(username, password_hash)
     if result == 0:
          newTok = authentication.generateToken(username);
          if newTok == -1:
               return("Error when generating token", 500)
          else:
               return(newTok, 200)
     elif result == 1:
          return("Wrong password", 400)
     elif result == -1:
          return("User does not exist",401)
Пример #32
0
def login(username, maxattempts=3):
    """This function authenticates a user in a login process.

    Args:
        username (str): A string representing the username of the user
        attempting to log in
        maxattempts (int, optional): An integer represent the maximum number
        of prompted attempts before the function returns False. Defaults to 3

    Returns:
        ok: True if the user has been authenticated; False otherwise

    Examples:
        Correct password entered on first attempt:
            >>> task_02.login('veruca', 2)
            Please enter your password:
            True
        Incorrect password entered maxattempts number of times:
            >>> task_02.login('veruca', 2)
            Please enter your password:
            True
    """
    aok = False
    i = 1
    getpw1 = 'Please enter your password: '******'Incorrect username or password. You have {} attempts left.'

    while (not aok) and (i <= maxattempts):
        if i == 1:
            aok = authentication.authenticate(username, getpass.getpass(getpw1))
        elif i > 1:
            print getpw2.format(maxattempts-i+1)
            aok = authentication.authenticate(username, getpass.getpass(getpw1))
        if aok:
            break
        i += 1
    return aok
Пример #33
0
def login(username, maxattempts=3):
    """This function decides whether password is authenticated.

    Args:
        username(str): the name of the user to authenticate.

        maxattempts(int): times that each username is allowed to try,
            default to 3.

    Returns:
        bool: True is the username and password are correct and didn't
            exceed more than maxattempts, else False.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        correct password entered on second attempt
        >>>task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        True

    """
    auth_mes = False
    en_pw1 = 'Please enter your password:'******'Incorrect username or password. You have {} attempts left.'
    num_tried = 1

    while (not auth_mes) and (num_tried <= maxattempts):
        auth_mes = authentication.authenticate(username,
                                               getpass.getpass(en_pw1))
        if auth_mes:
            auth_mes = True
        else:
            print en_pw2.format(maxattempts - num_tried)
        num_tried += 1
    return auth_mes
def login(username, maxattempts=3):
    """This function decides whether password is authenticated.

    Args:
        username(str): the name of the user to authenticate.

        maxattempts(int): times that each username is allowed to try,
            default to 3.

    Returns:
        bool: True is the username and password are correct and didn't
            exceed more than maxattempts, else False.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        correct password entered on second attempt
        >>>task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        True

    """
    auth_mes = False
    en_pw1 = 'Please enter your password:'******'Incorrect username or password. You have {} attempts left.'
    num_tried = 1

    while (not auth_mes) and (num_tried <= maxattempts):
        auth_mes = authentication.authenticate(username,
                                               getpass.getpass(en_pw1))
        if auth_mes:
            auth_mes = True
        else:
            print en_pw2.format(maxattempts - num_tried)
        num_tried += 1
    return auth_mes
Пример #35
0
def login(username, maxattempts=3):
    """This function authenticate user to login.

    This function use getpass module and prompt users to provide their passwords
    which will then be used to authenticate successfull login.

    Args:
        username(str): The username of the user attempting to log in.
        maxattempts(int, optional): The maximum number of prompted attempts.

    Returns:
        If true return true otherwise return false.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False
        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        True
    """

    authenticated = False
    attempt = 0
    warning = 'Incorrect username or password. You have {} attempts left.'

    while not authenticated and attempt < maxattempts:
        mypassd = getpass.getpass('Please enter your password:')

        if authentication.authenticate(username, mypassd) is True:
            authenticated = True

        else:
            attempt += 1
            print warning.format(maxattempts - attempt)
    return authenticated
Пример #36
0
def login(username, maxattempts=3):
    """This function authenticate user to login.

    This function use getpass module and prompt users to provide their passwords
    which will then be used to authenticate successfull login.

    Args:
        username(str): The username of the user attempting to log in.
        maxattempts(int, optional): The maximum number of prompted attempts.

    Returns:
        If true return true otherwise return false.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False
        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        True
    """

    authenticated = False
    attempt = 0
    warning = "Incorrect username or password. You have {} attempts left."

    while not authenticated and attempt < maxattempts:
        mypassd = getpass.getpass("Please enter your password:")

        if authentication.authenticate(username, mypassd) is True:
            authenticated = True

        else:
            attempt += 1
            print warning.format(maxattempts - attempt)
    return authenticated
Пример #37
0
def start_streaming(
        credential,
        target_db,
        target_coll,
        tracks=None,
        locations=None
):
    assert (tracks is not None) or (locations is not None)
    client = MongoClient(MG_CONN["URL"])
    coll = client[target_db][target_coll]
    listener = MongodListener(coll)
    auth = authenticate(credential)
    stream = Stream(auth, listener)
    if tracks is not None:
        stream.filter(track=tracks)
    elif locations is not None:
        stream.filter(locations=locations)
Пример #38
0
def authenticate(verbose):
    if verbose:
        print "Authenticating..."
        print
        print "Answering Questions..."
        print
    with open(QUESTION_PATH, "r") as questionFile:
        with open(SUBMISSION_PATH, "w") as submissionFile:
            next(questionFile)
            submissionFile.write(SUBMISSION_HEADER)
            questionReader = csv.reader(questionFile)
            for question in questionReader:
                qID, sID, dID = question
                if verbose and int(qID) % 1000 == 0:
                    print "	Now answering question", str(qID) + "..."
                prediction = authentication.authenticate(sID, dID)
                submissionFile.write(getCSVLine(qID, prediction))
Пример #39
0
def authenticate(verbose):
	if verbose:
		print "Authenticating..."
		print 
		print "Answering Questions..."
		print 
	with open(QUESTION_PATH, "r") as questionFile:
		with open(SUBMISSION_PATH, "w") as submissionFile:
			next(questionFile)
			submissionFile.write(SUBMISSION_HEADER)
			questionReader = csv.reader(questionFile)
			for question in questionReader:
				qID, sID, dID = question
				if verbose and int(qID)%1000 == 0 :
					print "	Now answering question", str(qID) + "..."
				prediction = authentication.authenticate(sID, dID)
				submissionFile.write(getCSVLine(qID, prediction))
Пример #40
0
def login(username, maxattempts=3):
    """
    This function prompts a username and password login.

    Args:
        username (str): username of the login
        maxattempts (int): # of attempts default = 3

    Returns:
        bool: True or False

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        True

    """
    authorization = False
    attempts = 1
    prompt = 'Please enter your password:'******'Incorrect username or password. You have {} attempts left.'
    while not authorization and attempts <= maxattempts:
        authorization = authentication.authenticate(username,
                                                    getpass.getpass(prompt))
        if authorization is True:
            authorization = True
        else:
            print fail_msg.format(maxattempts - attempts)
            attempts += 1
    return authorization
Пример #41
0
def writeList(value_list):
    json_file_name = 'hip-host-262902-bbbb44360c3f.json'
    credential = authentication.authenticate(json_file_name)
    gc = gspread.authorize(credential)
    wks = gc.open("domainTest").sheet1

    cell_list = wks.range('F1:F120')

    index = 0
    for cell in cell_list:
        if (index < len(value_list)):
            cell.value = value_list[index]
            index += 1

    for i in cell_list:
        print(i)

    wks.update_cells(cell_list)
def login(username, max_attempts=3):
    """This function loops through user input to authenticate password

    Args:
        It takes 2 arguments, username and max_attempts, with 3 as default max.

    Returns:
        A boolean
    """

    authenticated = False
    attempt = 0
    while (attempt < max_attempts) or (not authenticated):
        myval = getpass.getpass(prompt='Enter password:  ')
        attempt += 1
        authenticated = authentication.authenticate(username, myval)

    return authenticated
def login(username, max_attempts=3):
    """This function loops through user input to authenticate password

    Args:
        It takes 2 arguments, username and max_attempts, with 3 as default max.

    Returns:
        A boolean
    """

    authenticated = False
    attempt = 0
    while (attempt < max_attempts) or (not authenticated):
        myval = getpass.getpass(prompt='Enter password:  ')
        attempt += 1
        authenticated = authentication.authenticate(username, myval)

    return authenticated
Пример #44
0
def login(username, maxattempts=3):
    """This function checks for valid passoword for a given username.

    Args:
        username (string): The username.
        maxattempts (int, optional): The number of attempts allowed.
        The default is 3 attempts.

    Returns:
        Bool: True if the password matches. False if the password does not.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        True
        """
    authorization = False
    attempts = 1
    password = "******"
    msgfailure = "Incorrect password.  You have {} attempts remaining."
    while not authorization and attempts <= maxattempts:
        authorization = authentication.authenticate(username,
                                                    getpass.getpass(password))
        if authorization is True:
            authorization = True
        else:
            print msgfailure.format(maxattempts - attempts)
            attempts += 1
    return authorization
def login(username, maxattempts=3):
    """
    Args:
        username (string): username
        maxattemtps (int): maximum authentication attempts
    Returns:
        bool: True of false depending on authentication success.
    """
    if maxattempts < 1:
        print "Error, there must be at least one attempt to authenticate"
    if username:
        attempt = 0
        while attempt < maxattempts:
            mypass = getpass.getpass("Please enter your password: "******"Incorrect username of password. You have " + str(maxattempts - attempt) + " attempts left."
        return False
Пример #46
0
def login(username, maxattempts=3):
    """A function that prompts for and authenticates the password of a username.

    Args:
        username(str): A string representing the username of the user attempting
        to log in.
        maxattempts(int, optional): An integer represents the maximum number of
        prompted attempts before the functiion returns False. Defaults: Three

    Returns:
        boolean: A value of True or False if authentication succeeds.

    Examples:

        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

    """
    been_authenticated = False
    attempts = 0
    question = 'Please enter your password: '******'Incorrect username or password. You have {} attempts left.'

    while attempts < maxattempts:
        myval = getpass.getpass(question)

        if authentication.authenticate(username, myval):
            been_authenticated = True
            break
        else:
            attempts += 1
            print errormsg.format(maxattempts - attempts)

    return been_authenticated
def login(username, maxattempts=3):
    """This function will authenticate user(allows few attempts).

    Args:
        username (str): string that is username of user who is logging in
        maxattempts (int,optional): int rep maximum number of attempts

    Returns:
        boolean: T if successfully authen. F if exceed max number.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:greed
        True
    """
    incorrect = 'Incorrect username or password. You have {} attempts left.'
    authen = False
    numa = 0
    while not authen and numa < maxattempts:
        askpass = getpass.getpass('Please enter your password:')
        user = authentication.authenticate(username, askpass)
        if user is not False:
            authen = True
        else:
            numa += 1
            print incorrect.format(maxattempts - numa)
    return authen
Пример #48
0
def login(username, maxattempts=3):
    """This function will authenticate user(allows few attempts).

    Args:
        username (str): string that is username of user who is logging in
        maxattempts (int,optional): int rep maximum number of attempts

    Returns:
        boolean: T if successfully authen. F if exceed max number.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False

        >>> import task_02
        >>> task_02.login('veruca', 2)
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:greed
        True
    """
    incorrect = 'Incorrect username or password. You have {} attempts left.'
    authen = False
    numa = 0
    while not authen and numa < maxattempts:
        askpass = getpass.getpass('Please enter your password:')
        user = authentication.authenticate(username, askpass)
        if user is not False:
            authen = True
        else:
            numa += 1
            print incorrect.format(maxattempts - numa)
    return authen
Пример #49
0
	def POST(self):
		zones_interdites = model.getZoneInterdites()
		print("POST Submitted")
		i = web.input()
		print(i) #printing the post vars
		# We received a POST from the login form
		if i.submitlogin != None :
			postVars = dict(login=i.login, password=i.password)
			auth_results = authentication.authenticate(postVars)
			# print(auth_results)
			if auth_results['login_validated'] == True :
				authentication.register_login(session,auth_results)
				view_msg ="successfully logged in"
				print session.__dict__
				return render.index(session, zones_interdites)
			else :
				view_msg ="Bad authentication"
				return render.index(None, zones_interdites)
		else :
			return render.index(None, zones_interdites)
Пример #50
0
def create_note():
    user = authenticate(request)

    if user is None:
        response.status = 401
        return {'error': 'Authentication credentials not valid.'}

    body = request.body.read()
    errors = note_schema.validate(json.loads(body))

    if errors:
        response.status = 400
        return {'errors': errors}

    note_dict = note_schema.loads(body).data

    note = Note.create(title=note_dict.get('title', ''),
                       content=note_dict.get('content', ''),
                       owner=user.id)
    return note_schema.dumps(note).data
def login(username, maxattempts=3):
    """This function checks username and password for correctness.

    Args:
        username (str): A string representing the username of the user
        attempting to log in.
        maxattempts (int, optional): An integer represent the maximum number of
        prompted attempts before the function returns False.

    Returns:
        Returns a True or False in the process of authentication of attampts

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False
    """
    authenticated = False
    counter = 1

    inputmsg = 'Please enter your password: '******'Incorrect username or password. You have {0} attempts'

    while counter <= maxattempts:
        password = getpass.getpass(inputmsg)
        message = authentication.authenticate(username, password)
        if message:
            authenticated = True
            break
        else:
            print errormsg.format(maxattempts - counter)
            counter += 1
        return authenticated
Пример #52
0
def login(username, maxattempts=3):
    """ Defines a function to represent the login username and maximum number
    of attempts permitted.

    Args:
        username(str): A string representing the username
        maxattempts(int): An optional value representing the maximum number
        of prompted attempts

    Returns:
        True or false value depending on whether password is authenticated

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.


    """

    authenticated = False
    numattempts = 0
    error = 'Incorrect username or password. You have {0} attempts left.'
    while authenticated is False and numattempts < maxattempts:
        password = getpass.getpass('Please ender your password:')

        if authentication.authenticate(username, password) is True:
            authenticated = True
        else:
            numattempts += 1
            print error.format(maxattempts - numattempts)

    return authenticated
def login(username, maxattempts=3):
    """login authenticates user to login.

    Args:
        username(str): enter username
        maxattempts(int, optional): The max number of prompted attempts.

    Returns:
        If true return true otherwise return false.

    Examples:
        >>> import task_02
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False
    """

    authenticated = False
    attempt = 0
    warning = 'Incorrect username or password. You have {} attempts left.'

    while not authenticated and attempt < maxattempts:
        mypassd = getpass.getpass('Please enter your password:')

        if authentication.authenticate(username, mypassd) is True:
            authenticated = True

        else:
            attempt += 1
            print warning.format(maxattempts - attempt)
    return authenticated
def login(username, maxattempts=3):
    """Login to see top secret files

    Args:
        username (str): Enter username
        maxattempts (int): Number of attempts, default 3.

    Returns:
        (bool):True if password is right, False if password is wrong.

    Examples:
        >>> task_02.login('mike', 4)
        Please enter your password:
        Incorrect username or password. You have 3 attempts left.
        Please enter your password:
        Incorrect username or password. You have 2 attempts left.
        Please enter your password:
        Incorrect username or password. You have 1 attempts left.
        Please enter your password:
        Incorrect username or password. You have 0 attempts left.
        False
    """

    auth = False
    nope = 'Incorrect username or password. You have {} attempts left.'

    while auth is False and maxattempts > 0:
        password = getpass.getpass('Please enter your password:')
        auth = authentication.authenticate(username, password)

        if auth is not False:
            auth = True

        else:
            maxattempts -= 1
            print nope.format(maxattempts)

    return auth
Пример #55
0
def authenticate_event(json, methods=['GET', 'POST']):
    """
    The event for authenticating clients
    """
    pid = json["pid"]

    client = get_client(request.sid)

    if (not client.authenticated):
        client.authenticated = authentication.authenticate(pid)
    if client.authenticated:
        client.name = authentication.getName(pid)
        json = {
            "id": client.id,
            "name": client.name,
            "backgroundColor": client.backgroundColor,
            "userIconSource": client.userIconSource
        }
        socketio.emit("client_details_changed", json)
        send_info_message(200, "Du är nu autentiserad", request.sid)
    else:
        send_info_message(400, "Det uppstod ett fel vid autentisering",
                          request.sid)