-6

I need to create a system that checks a file for the username and password and if it is correct, it says whether or not in a label. So far I have been able to simply make one username and password equal to the variable, but need to link it to a file somehow..

String user_pass;

String user_name;

user_name= txtUser.getText().tostring();

user_pass= txtPass.getText().tostring();

if( user_name.equals("mube123") && user_pass.equals("mubarik") ){

    lblDisplay.setText("Credentials Accepted.");
}
else{

    lblDisplay.setText("Please try again.");

}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140

1 Answers1

3

Your question is a bit ambiguous and I think you need to clarify some things like:

  • how do clients access the file in the first place? Through a local tool / through the web browser / ... ?
  • where is the list of valid credentials supposed to be stored? In an identity store such as "LDAP" or "ActiveDirectory" / hardcoded in your program / in a local file?

Depending on what your answers to these questions is, the solutions you want to look at vary quite a lot. For example:

  • when you have a user with access to the protected file itself and want him to prevent reading the content without the right username+password, you need to encrypt the file.
  • when you have a user that wants to download the file from a webserver, you can use the existing protection mechanisms of your webserver (e.g. ".htaccess" file protection)

Without known what your are trying to achieve, it is not possible to answer the question ;)

Ray
  • 686
  • 3
  • 6