Let the ERP system remember the Login Password

Source: Internet
Author: User

In practical applications, users may need to record the ERP password and do not want to enter the password each time they log on, just like QQ.

Below is the code for C:

REFERENCE The following namespace first

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Management;using System.Windows.Forms;using System.IO;using System.Xml;using System.Xml.Linq;

The Code is as follows:

/// <Summary> /// Save the logon password /// </Summary> /// <Param name = "diskid"> hard disk id </param> /// <param name = "deptid"> department ID </param> /// <Param name = "uid"> User Name </param> /// <Param name = "PWD"> password </param> /// <Param name = "issave"> whether to save </param> /// <returns> </returns> Public bool savepassword (string diskid, int deptid, string uid, string PWD, bool issave) {bool flag = false; try {string xmlfile = application. startuppath + "\ User. xml"; if (! File. exists (xmlfile) {xdocument xdoc = new xdocument (); xdoc = new xdocument (New xdeclaration ("1.0", "UTF-8", "yes "), new xelement ("users", new xattribute ("ID", diskid); xdoc. save (xmlfile);} xdocument Doc = xdocument. load (xmlfile); xelement Xe = Doc. element ("users"); If (diskid = Xe. attribute ("ID "). value. tostring () {// first check whether the user var PWDs = from un in Xe has been saved. descendants ("Dept") where UN. attribute ("ID "). value = deptid. tostring () & UN. attribute ("username "). value = uid Select UN; // if it is saved, modify the user name, password, or add the user name and password node if (issave) {If (PWDs. count ()> 0) {foreach (VAR node in PWDs) {node. attribute ("password "). value = PWD ;}} else {xelement Xel = new xelement ("Dept"); Xel. add (New xattribute ("ID", deptid); Xel. add (New xattribute ("username", UID); Xel. add (New xattribute ("password", PWD); Xe. add (Xel) ;}} else {If (PWDs. count ()> 0) {// Delete the saved account and password xelement node = (xelement) PWDs. singleordefault (); node. remove () ;}} Doc. save (xmlfile) ;}} catch (exception ex) {flag = false ;}return flag ;}

The following is the password for reading the user:

/// <Summary> /// read the saved User Password /// </Summary> /// <Param name = "diskid"> hard disk id </param> // /<Param name = "deptid"> department ID </param> // <Param name = "uid"> User Name </param> /// <returns> </returns> Public String readpassword (string diskid, int deptid, string UID) {string Pwd = ""; try {string xmlfile = application. startuppath + "\ User. XML "; if (! File. exists (xmlfile) {return "";} xdocument Doc = xdocument. load (xmlfile); xelement Xe = Doc. element ("users"); // first, check whether the user var PWDs = from un in Xe has been saved. descendants ("Dept") where UN. attribute ("ID "). value = deptid. tostring () & UN. attribute ("username "). value = uid Select UN; If (PWDs. count ()> 0) {foreach (VAR node in PWDs) {Pwd = node. attribute ("password "). value ;}} catch (exception ex) {Pwd = "";} return PWD ;}

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.