📄 checkuserinfo.java
字号:
package remote;import java.io.File;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;public class CheckUserInfo{ private String CurrentUser; private String host; private String addr; private String user; private String psw; private String userInfoFile = "user.xml"; public CheckUserInfo(){ } public CheckUserInfo(String n){ CurrentUser = n; } public boolean checkUser(String n, String p) { String decrypted; try { File file = new File(userInfoFile); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); System.out.println("Root element " + doc.getDocumentElement().getNodeName()); NodeList userList = doc.getElementsByTagName("user"); int userCount = userList.getLength(); for (int s = 0; s < userCount; s++) { Node firstUserNode = userList.item(s); if (firstUserNode.getNodeType() == Node.ELEMENT_NODE) { Element firstUserElement = (Element) firstUserNode; NodeList NameList = firstUserElement.getElementsByTagName("name"); Element NameElement = (Element) NameList.item(0); NodeList Name = NameElement.getChildNodes(); String name = ((Node) Name.item(0)).getNodeValue(); System.out.println("Name : " + name); NodeList PasswordList = firstUserElement.getElementsByTagName("password"); Element PasswordElement = (Element) PasswordList.item(0); NodeList Password = PasswordElement.getChildNodes(); String password = ((Node) Password.item(0)).getNodeValue(); System.out.println("Password: " + password); decrypted = Encoder.decrypting(password); if (n.equals(name) && p.equals(decrypted)){ System.out.println("Get Correct User"); CurrentUser = n; return true; } } } } catch (Exception e) { e.printStackTrace(); } return false; } public void getEmailDetails(){ String encryptedPsw; try { System.out.println("Getting Email Information from xml"); File file = new File(userInfoFile); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(file); doc.getDocumentElement().normalize(); NodeList nodeLst = doc.getElementsByTagName("user"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element fstElmnt = (Element) fstNode; NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("name"); Element fstNmElmnt = (Element) fstNmElmntLst.item(0); NodeList fstNm = fstNmElmnt.getChildNodes(); String name = ((Node) fstNm.item(0)).getNodeValue(); if (CurrentUser.equals(name)){ NodeList newNmElmntLst = fstElmnt.getElementsByTagName("email"); for (int k = 0; k < newNmElmntLst.getLength(); k++){ Node emailNode = newNmElmntLst.item(k); if (emailNode.getNodeType() == Node.ELEMENT_NODE){ Element emailElmnt = (Element) emailNode; NodeList EmailElmntLst1 = emailElmnt.getElementsByTagName("host"); Element EmailElmnt1 = (Element) EmailElmntLst1.item(0); NodeList Email1 = EmailElmnt1.getChildNodes(); host = ((Node) Email1.item(0)).getNodeValue(); NodeList EmailElmntLst2 = emailElmnt.getElementsByTagName("addr"); Element EmailElmnt2 = (Element) EmailElmntLst2.item(0); NodeList Email2 = EmailElmnt2.getChildNodes(); addr = ((Node) Email2.item(0)).getNodeValue(); NodeList EmailElmntLst3 = emailElmnt.getElementsByTagName("login"); Element EmailElmnt3 = (Element) EmailElmntLst3.item(0); NodeList Email3 = EmailElmnt3.getChildNodes(); user = ((Node) Email3.item(0)).getNodeValue(); NodeList EmailElmntLst4 = emailElmnt.getElementsByTagName("psw"); Element EmailElmnt4 = (Element) EmailElmntLst4.item(0); NodeList Email4 = EmailElmnt4.getChildNodes(); encryptedPsw = ((Node) Email4.item(0)).getNodeValue(); psw = Encoder.decrypting(encryptedPsw); return; } } } } } } catch (Exception e) { e.printStackTrace(); } } public String getEmailHost(){ return host; } public String getEmailAddr(){ return addr; } public String getEmailUser(){ return user; } public String getEmailPsw(){ return psw; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -