Hướng dẫn python code to enter password - mã python để nhập mật khẩu

9 ví dụ mã Python được tìm thấy liên quan đến "mật khẩu đầu vào". Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. input password". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

ví dụ 1

def input_change_password():
    print "\n-------change password---------\n"
    login = raw_input("Login: ")
    password = getpass.getpass("New password: ")
    password_confirm = getpass.getpass("Password confirmation: ")
    if password != password_confirm:
        print "Password doesn't match"
        return
    change_password(login, password)
    print "Password updated!" 

Ví dụ 2

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 

Ví dụ 3

def input_password(self, message=None):
        """
        Prompt the user for a password or other confidential data.

        This is equivalent to the input() method, but does not echo inputted characters to the screen.

        Args:
            message (str): The prompt message.

        Returns:
            str: The password provided by the user.
        """
        message = self.__prompt_formatter.format_prompt(message)
        try:
            if message:
                return getpass.getpass(message)
            else:
                return getpass.getpass()
        except BaseException:
            self.__screen.println('Warning: Unable to mask input; characters will be echoed to console')
            return self.input(message) 

Ví dụ 4

def addPasswordInput(self):
        """self.addPasswordInput(name, value) -> True if successful.
Add a password input knob to the panel.
@param name: The name for the new knob.
@param value: The initial value for the new knob.
@return: True if successful.
"""
        pass 

Ví dụ 5

def input_ask_password(self, prompt):
        if self._user_input_requester:
            try:
                return self._user_input_requester.ask_password(prompt)
            except IOError as e:
                raise FatalPluginError("User input error: {0}".format(e))
            except NotImplementedError:  # ignore this and raise a FatalPluginError
                pass
        raise FatalPluginError("This plugin requires user input, however it is not supported on this platform") 

Ví dụ 6

def input_password(self, request, content, model, templateAttributes={}):
        return content.input(
            type="password",
            size=str(templateAttributes.get('size', "60")),
            name=model.name) 

Ví dụ 7

def addPasswordInput(self):
        """self.addPasswordInput(name, value) -> True if successful.
Add a password input knob to the panel.
@param name: The name for the new knob.
@param value: The initial value for the new knob.
@return: True if successful.
"""
        pass 

Ví dụ 8

def input_password(self, locator, text):
        """Types the given password into text field identified by `locator`.

        Difference between this keyword and `Input Text` is that this keyword
        does not log the given password. See `introduction` for details about
        locating elements.
        """
        self._info("Typing password into text field '%s'" % locator)
        self._element_input_text_by_locator(locator, text) 

Ví dụ 9

def inputPassword():
	password = getpass.getpass()
	print("Re-enter")
	repassword = getpass.getpass()

	if password != repassword:
		print("Passwords don't match. Try again")
		return inputPassword()
	return password 

Tôi đang cố gắng tạo một chương trình cơ bản yêu cầu người dùng nhập và sau đó nhập lại mật khẩu. Nếu nó phù hợp, thì nó sẽ in "Mật khẩu được tạo". Nếu không, nó sẽ tiếp tục yêu cầu người dùng thử lại cho đến khi mật khẩu khớp.

Đây là những gì tôi có cho đến nay; Tôi biết một vòng lặp và ít nhất một câu lệnh "nếu" khác là cần thiết, nhưng tôi không biết làm thế nào để làm điều đó.

password=raw_input("please select a password")
password_again=raw_input("please re-type your password")
loop=raw_input("Password does not match. Please try again")
if password_again==password:
      print("password created")
else: raw_input(loop)

Trợ giúp được đánh giá cao!

Đã hỏi ngày 6 tháng 3 năm 2014 lúc 4:07Mar 6, 2014 at 4:07

Tôi nghĩ rằng sử dụng mô -đun GetPass sẽ là một quyết định khôn ngoan: nó sẽ nhắc người dùng về mật khẩu mà không lặp lại It will Prompt the user for a password without echoing

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
0

Output:

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
1

Đã trả lời ngày 6 tháng 3 năm 2014 lúc 4:26Mar 6, 2014 at 4:26

Hướng dẫn python code to enter password - mã python để nhập mật khẩu

James Sapamjames SapamJames Sapam

15.3k11 Huy hiệu vàng47 Huy hiệu bạc68 Huy hiệu Đồng11 gold badges47 silver badges68 bronze badges

1

Đây là một cách tuyệt vời để tìm hiểu trong khi các vòng lặp

Yêu cầu các giá trị

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
2

Vòng lặp cho đến khi chúng khớp

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
3

Đã trả lời ngày 6 tháng 3 năm 2014 lúc 4:13Mar 6, 2014 at 4:13

PynewbiepynewbiePyNEwbie

4.8304 Huy hiệu vàng37 Huy hiệu bạc85 Huy hiệu Đồng4 gold badges37 silver badges85 bronze badges

Đó không phải là một vòng lặp, sử dụng

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
6 và
def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
7:

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
4

Đã trả lời ngày 6 tháng 3 năm 2014 lúc 4:16Mar 6, 2014 at 4:16

Hướng dẫn python code to enter password - mã python để nhập mật khẩu

Zhangxaochenzhangxaochenzhangxaochen

31.6K15 Huy hiệu vàng73 Huy hiệu bạc106 Huy hiệu đồng15 gold badges73 silver badges106 bronze badges

3

Cách đơn giản nhất là sử dụng chức năng

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
8 như thế này

def input_password(optdict, question='password:'):
    from getpass import getpass
    while True:
        value = getpass(question)
        value2 = getpass('confirm: ')
        if value == value2:
            return value
        print('password mismatch, try again') 
5

Đã trả lời ngày 6 tháng 3 năm 2014 lúc 4:21Mar 6, 2014 at 4:21

Hướng dẫn python code to enter password - mã python để nhập mật khẩu

Thefourtheyethefourtheyethefourtheye

227K52 Huy hiệu vàng443 Huy hiệu bạc486 Huy hiệu Đồng52 gold badges443 silver badges486 bronze badges

2