arrays - Java username and password always returns true -
I am working on a project and am trying to redeem the username / password. Below you see the code whenever I click on the login button, the username changes to bobsyouruncle, indicating that the "true" value is found in the method. The problem is that regardless of input, it always makes it even more confusing because if I change the "return right" for the "return back", then I can still obtain bobsurunal. ? Any suggestion
loginButton.addActionListener (New ActionListener) {@Override Public Null ActionPerformed (ActionEvent event) {Boolean = AuthenticateCredentials (usernameField.getText (), passwordField.getPassword Authenticated ()); (Certified = true) {usernameField.setText ("Bobsyouruncle");} and {System.exit (0);}}}); The method below is accessible.
Personal Boolean AuthenticateCredentials (string user, four [] passed) {// This is only a placeholder. String the Coin Encerer = "42"; String the cost user = "fift"; Four [] passcode = theCortAnswer.toCharArray (); OptionPanel.showInternalMessageDialog (SecurityPanel, "Egg should not be green."); If (user.file (Corfat User) and ARRIAZELS (passcode, pass)) {return true; } Other {return false; }} If someone wants to tell me that I am already screwing up a safe user name and password to disturb the road, then he will also bundle.
The problem here is that you compare two expressions with the = symbol , Which means assignment is the comparison symbol == in Java.
However, if you change your code like this:
if (certified == true) you still have to Comparing with primitive type ( Boolean ) ( boolean ).
The correct way to do this is to use boolean .
Private Boolean AuthenticateCredentials (string user, four [] passed) {return: return value of your function form boolean to boolean Change (user.equals ("FPrefect") & amp; Arrays.equals ("42" .toCharArray (), passed);} Then, in your button listener Similar:
Boolean authenticated = AuthenticateCredentials (usernameField.getText (), passwordField.getPassword ()); if (authenticated) usernameField.setText ("Bobsyouruncle"); Rest System.exit (0 );
Comments
Post a Comment