
正文
java中记住密码的代码 java中记住密码的代码怎么写
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java中怎样实现记住密码
public void savaFile(){//选择保存密码
File f=new File(".\\data\\dk.txt");
try {
FileWriter txt=new FileWriter(f);
txt.write(yh.getText()+"-");
txt.write(mm.getText()+"+");
txt.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void savaFile1(){//未选择保存密码
File f=new File(".\\data\\dk.txt");
try {
FileWriter txt=new FileWriter(f);
txt.write(yh.getText()+"-");
txt.write(""+"+");
txt.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
public void Duqu() {//读取文件中保存的账号和密码
FileReader fr;
try {
fr = new FileReader(".\\data\\dk.txt");
BufferedReader br = new BufferedReader(fr);
try {
String line = br.readLine();
yh.setText(line.toString().substring(0,line.toString().indexOf('-')));
mm.setText(line.toString().substring(line.toString().indexOf('-')+1,line.toString().indexOf('+')));
//System.out.print(line);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
相关问答
Q1: 我用jsp做了个登录页面,想让它记住密码,下次登录时不需要再输入密码,怎样实现?
使用Cookie实现。
一、当用户输入用户名密码时,到控制层用 Cookie user = new Cookie("user",name+"-"+passward); 加到cookie中,然后在访问此登录页面时,就先调用 Cookie[] cookies=request.getCookies(); 看cookie中是否有user这个值,如果有就取得用户名、密码。
二、代码%@ page language="java" import="java.util.*" pageEncoding="utf-8"% % String name="nihao"; String passward="nihao"; try{ Cookie user = new Cookie("user",name+"-"+passward); user.setMaxAge(60); response.addCookie(user); Cookie[] cookies=request.getCookies(); if(cookies!=null){ for(int i=0;icookies.length;i++){ if(cookies[i].getName().equals("user")){ 。
三、用两个TextBox,一个按钮控件来实现的,并且用了一个CheckBox控件来通过cookie实现记住密码的功能,现在的问题是, 输入密码的那个TextBox控件的TextMode属性为SingleLine或MultiLine。
Q2: 怎样用Java 如何实现“记住密码”功能?
把你的密码写到文件中(一般是:.properties文件)java中记住密码的代码,用键值对(set或map)的方式去读取文件;
文件内容是这样的:
用户名1=密码1
用户名2=密码2
···
//根据key读取value
public static String readValue(String filePath,String key) {
Properties props = new Properties();
Property property=new Property();
try{
key=new String(key.getBytes("GB2312"),"ISO-8859-1");
key= Entropy.encrypt(key, "123");
}catch (UnsupportedEncodingException ex){}
try {
InputStream in = new BufferedInputStream (new FileInputStream(filePath));
props.load(in);
String value = new String(props.getProperty (key).getBytes("ISO-8859-1"),"GB2312");
value= Entropy.decrypt(value, "123");
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
为了密码安全,还要用到加密算法,把加密处理的数据写到文件中,你百度DES或者AES加密算法,都有现成的例子。
还不懂的话群里找java中记住密码的代码我:咖啡编程——57914814
关于java中记住密码的代码和java中记住密码的代码怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








