gpt4 book ai didi

java - 在类中保存密码的最理想方式 - Java

转载 作者:行者123 更新时间:2023-12-03 20:26:01 27 4
gpt4 key购买 nike

我有两个类“用户配置文件”和“指纹配置文件”,它们扩展了一个抽象类“配置文件”。

轮廓:

/**
* Template for User profiles or Fingerprint profiles
*/
public abstract class Profile {

/**
* Profile Name
*/
private String name;

/**
* Profile id
*/
private int id;

/**
* Set the name of this profile
* @param name
*/
public void setProfileName(String name) {
this.name = name;
}

/**
* Set the id of this profile
* @param name
*/
public void setIdNumber(int id) {
this.id = id;
}

/**
* Get the name of this profile
*/
public String getProfileName() {

return name;

}

/**
* Get the id of this profile
*/
public int getIdNumber() {
return id;
}

}

我的下一个类是 UserProfile
public class UserProfile extends Profile {

/**
* Users password
*/
private char[] password;

/**
* Set User password
* @param password
*/
public void setPassword(char[] password){

this.password = password;

}

/**
* Get User password
*/
public char[] getPassword(){

return password;

}

}

仅仅看这个类似乎很狡猾,能够像这样检索密码似乎是完全错误的(即使 get 方法是 private )。

在制作我的 FingerPrintProfile 类以及包含本质上也需要安全的“FingerprintData”对象时,似乎我将面临同样的问题。

有没有人知道一种安全的方法,或者最好是人们用来解决这种情况的模式?

谢谢 !

奖金问题

我创建了抽象类来为两种类型的配置文件提供模板,指纹数据和文本密码之间似乎有一个共同点。但是,不可能创建一个抽象字段“密码”,它可能是一个字符数组或一个 FingerprintData 对象。有任何想法吗??

最佳答案

使用密码时,您可能应该使用某种形式的加密,这样密码就不会以纯文本形式存储。您可以阅读它的工作原理 here .

Here是 Bcrypt 的 Java 实现的链接,它至少应该可以帮助您入门。

关于java - 在类中保存密码的最理想方式 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13955515/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com