0

[パスワードの変更] ボタンをプログラミングしていますが、テキスト ファイルに保存されているパスワードを上書きする際に問題が発生しています。

ユーザー名とパスワードがそれぞれテキスト ファイルに保存されているとします。

John01

1871993

$$$

Jessica

123456

$$$

(...)

たとえば、user: John01 の現在のパスワード "1871993" を、[パスワードの変更] ボタンをクリックした後に入力した新しいパスワードで上書きするにはどうすればよいですか?

私が今持っているのは、同じユーザー名を新しいパスワードで保存することだけです。

これは私のパスワード変更ボタンのコードです:

if (ChangePassword())
{
    if (EnterCurrentPasswordTextField.getText().trim().length() != 0 
        && NewPasswordTextField.getText().trim().length() != 0
        && ConfirmNewPasswordTextField.getText().trim().length() != 0)
    {

        if (NewPasswordTextField.getText().equals(ConfirmNewPasswordTextField.getText()))
        {


                FileWriter out = null;
            try{
                out = new FileWriter("login.txt", true);

                out.append(System.getProperty("line.separator"));          
                out.append(NameTextField.getText());
                out.append(System.getProperty("line.separator"));
                out.append(ConfirmNewPasswordTextField.getText());
                out.append(System.getProperty("line.separator"));
                out.append(System.getProperty("line.separator"));
                out.append("$$$");
                out.append(System.getProperty("line.separator"));
                out.close();
                out=null;
                }catch(IOException ioe){
                    NameTextField.setText("IOProblem");
                    }

                StatusMessageLabel.setText(NameTextField.getText() + " you have succesfully changed your password");
                MainTabbedPane.setEnabledAt(0, false);  
                MainTabbedPane.setEnabledAt(1, true);
                MainTabbedPane.setEnabledAt(2, true);
                MainTabbedPane.setEnabledAt(3, true);        
                MainTabbedPane.setEnabledAt(4, true);
                MainTabbedPane.setEnabledAt(5, false);
                MainTabbedPane.setSelectedIndex(2);

        }
        else {
            StatusMessageLabel.setText("ERROR: Please confirm your New Password is identical in both fields!");
        }
    }
    else {
        StatusMessageLabel.setText("ERROR: Please enter all empty fields!");
    }    
}    
else {
    StatusMessageLabel.setText("ERROR: Wrong Current Password Details!!");
}
4

2 に答える 2

1

現在のパスワード/ユーザー名ファイルをマップにロードして、エントリを見つけ、マップエントリを書き出します。おそらく、より良い解決策は、ある種のメモリデータベースを使用することです。

于 2013-02-22T13:43:26.363 に答える
0

を使用するのはどうですかMappedByteBuffer

于 2013-02-22T13:47:33.217 に答える