Added the SSH password saving and automatic login function for Putty 0.6

Source: Internet
Author: User

1. setup_config_box:
Putty's interface processing method is worth studying. First, consider where to put the newly added passowrd text box on the original interface, I personally think it is a good choice to put the newly added text box behind the original input port.
Modify: line: 1155 rows

Ctrl_columns (s, 2, 75, 25 );

Change

Ctrl_columns (s, 3, 50, 25, 25 );

The following number is only a ratio.
Add: line: 1165 and then add:


C = ctrl_editbox (s, HOST_PASSWORD, NO_SHORTCUT, 100,
HELPCTX (session_hostname ),
Configure_userpassword_handler, I (0), I (0 ));
C-> editbox. password = 1;
C-> generic. column = 2;
Hp-> username = c;

Define the HOST_PASSWORD macro at the beginning of the file. If this macro is not defined, replace it with a string.

# Define HOST_PASSWORD "Password"

2. Add a text box for entering password. Add the configure_userpassword_handler function to any location. This function controls the passowrd input box.

Static void configure_userpassword_handler (union control * ctrl, void * dlg, void * data, int event)
{
Config * cfg = (Config *) data;
If (event = EVENT_REFRESH ){
HWND hWnd = dlg_get_control_handle (ctrl, dlg );
If (cfg-> protocol = PROT_SERIAL) {/* dont need password for serail port */
If (hWnd) EnableWindow (hWnd, 0 );
} Else {
If (hWnd) EnableWindow (hWnd, 1 );
Dlg_editbox_set (ctrl, dlg, cfg-> password );
}
} Else if (event = EVENT_VALCHANGE ){
If (cfg-> protocol! = PROT_SERIAL ){
Dlg_editbox_get (ctrl, dlg, cfg-> password, lenof (cfg-> password ));
}
}
}

3. Modify the struct hostport structure:

Struct hostport {
Union control * host, * port, * username;
};

4. Modify config_protocolbuttons_handler: add

Dlg_refresh (hp-> username, dlg );

==> Wintrls. c

Add function:

HWND dlg_get_control_handle (union control * ctrl, void * dlg)
{
Struct dlgparam * dp = (struct dlgparam *) dlg;
Struct winctrl * c = dlg_findbyctrl (dp, ctrl );
HWND hw = GetDlgItem (dp-> hwnd, c-> base_id + 1 );
Return hw;
}

The purpose of this function is to obtain the window handle of the text box.

====> Dialog. h

Declaration of adding a function:

HWND dlg_get_control_handle (union control * ctrl, void * dlg );

====> Putty. h

Modify struct config_tag: add

Char password [104];

(The maximum allowed password in Putty is 100 characters)

====> Settings. c
Add the following in the save_open_settings function:

Write_setting_ B (sesskey, "Password", cfg-> password );

Add the following to the load_open_settings function:

Gpps (sesskey, "Password", "", cfg-> password, sizeof (cfg-> password ));

====> Ssh. c
In the do_ssh1_login function, the code after line 1 is changed:
If the password to be saved is empty, it will be processed according to the original process; otherwise, the saved password will be copied directly. If (! Ret) the process remains unchanged.

If (strlen (ssh-> cfg. password) = 0 ){
Ret = get_userpass_input (s-> cur_prompt, NULL, 0 );
While (ret <0 ){
Ssh-> send_ OK = 1;
CrWaitUntil (! Pktin );
Ret = get_userpass_input (s-> cur_prompt, in, inlen );
Ssh-> send_ OK = 0;
}
} Else {
Ret = 1;
Strcpy (s-> cur_prompt-> prompts [0]-> result, ssh-> cfg. password );
}

In the do_ssh2_authconn function, the code after line 1 is changed:

If (strlen (ssh-> cfg. password) = 0 ){
Ret = get_userpass_input (s-> cur_prompt, NULL, 0 );
While (ret <0 ){
Ssh-> send_ OK = 1;
CrWaitUntilV (! Pktin );
Ret = get_userpass_input (s-> cur_prompt, in, inlen );
Ssh-> send_ OK = 0;
}
}
Else {
Ret = 1;
Strcpy (s-> cur_prompt-> prompts [0]-> result, ssh-> cfg. password );
}

====> Version. c
Add files

# Define RELEASE 0.60

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.