WinForm Remember password function

Source: Internet
Author: User

Login
private void Btn_login_click (object sender, EventArgs e)
{
Remember the password
if (Cb_remember. Checked = = True)
{

Write the user name and password to the Xtflz.dll file in the program running directory
Writeini ("My section", This.tb_UserName.Text.ToString (), this.tb_Password.Text.ToString (),
String. Format (@ "{0}\xtflz.dll", application.startuppath));
MessageBox.Show ("write success");
}
Else
{
Writeini ("My section", This.tb_UserName.Text.ToString (), "",
String. Format (@ "{0}\xtflz.dll", application.startuppath));
}
}
#region Login Remember Password
<summary>
Provides a write operation for the INI file (if both key and value are empty (null), then all key values (including section names) under the sections specified by the stanza are removed [if value is null (NULL), delete the key key value])
</summary>
<param name= "section" > Specified stanza name </param>
<param name= "key" > Specified key name </param>
<param Name= The value of the "value" >key (the appropriate type Ing,long ... Convert to String type) </param>
<param name= "FilePath" >ini file full path </param>
<returns></returns>
public static bool Writeini (string section, String Key, String Value, String FilePath)
{
Successful return non-zero
Long lre = writeprivateprofilestring (section, Key, Value, FilePath);
return lre = = 0L? False:true;
}
<summary>
Provides read operation of INI file
</summary>
<param name= "section" > Specified stanza name </param>
<param name= "key" > Specified key name </param>
<param name= "FilePath" >ini file full path </param>
<returns> Convert the string type to the type of the corresponding Int,long (the return value should not exceed 255 characters) </returns>
public static string Readini (String section, String Key, String FilePath)
{
int Size = 255;
StringBuilder restr = new StringBuilder (255);
GetPrivateProfileString (section, Key, "ERROR ...", Restr, Size, FilePath);
if (restr.tostring () = = "ERROR ...")
{
return null;
}
return restr.tostring ();
}
<summary>
C # declaration INI file write operation function writeprivateprofilestring ()
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Value" ></param>
<param name= "FilePath" ></param>
<returns></returns>
Read/write INI file function
[System.Runtime.InteropServices.DllImport ("kernel32")]
public static extern long WritePrivateProfileString (string section,
The specified section name
String Key,
The specified key name
String Value,
String FilePath);
<summary>
C # declaration INI file read operation function getprivateprofilestring
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Def" ></param>
<param name= "RetVal" ></param>
<param name= "Size" ></param>
<param name= "FilePath" ></param>
<returns></returns>
[System.Runtime.InteropServices.DllImport ("kernel32")]
public static extern int GetPrivateProfileString (string section,
The specified section name
String key,
The specified key name
String Def,
Returns the custom string if the correct value is not obtained
StringBuilder RetVal,
Save String value
int Size,
Specifies the length of the retval
String FilePath);
INI file path (if the INI file is not within the operating system folder, you must specify an absolute path to the INI file)
#endregion Login Remember Password
private void Tb_username_textchanged_1 (object sender, EventArgs e)
{
string s = this.tb_UserName.Text.ToString ();
string result = Readini ("My section", S, String. Format (@ "{0}\xtflz.dll", application.startuppath));
if (result = = NULL | | result = = "")
{
This.tb_Password.Text = "";
This.cb_remember. Checked = false;
}
Else
{
This.tb_Password.Text = result;
This.cb_remember. Checked = true;
}
}

WinForm Remember password function

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.