Guest User

Untitled

a guest
Jan 17th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. String pass;
  2. String user;
  3. user = txtUser.getText();
  4. pass = txtPass.getText();
  5.  
  6. if(pass.equals("blue") && user.equals("bob") ){
  7. lblDisplay.setText("Credentials Accepted.");
  8. }
  9. else{
  10. lblDisplay.setText("Please try again.");
  11. }
  12.  
  13. import java.util.Scanner; // I use scanner because it's command line.
  14.  
  15. public class Login {
  16. public void run() {
  17. Scanner scan = new Scanner (new File("the\dir\myFile.extension"));
  18. Scanner keyboard = new Scanner (System.in);
  19. String user = scan.nextLine();
  20. String pass = scan.nextLine(); // looks at selected file in scan
  21.  
  22. String inpUser = keyboard.nextLine();
  23. String inpPass = keyboard.nextLine(); // gets input from user
  24.  
  25. if (inpUser.equals(user) && inpPass.equals(pass)) {
  26. System.out.print("your login message");
  27. } else {
  28. System.out.print("your error message");
  29. }
  30. }
  31. }
  32.  
  33. import java.util.Scanner;
  34. public class BATM {
  35.  
  36. public static void main(String[] args) {
  37. Scanner input = new Scanner(System.in);
  38.  
  39. String username;
  40. String password;
  41.  
  42. System.out.println("Log in:");
  43. System.out.println("username: ");
  44. username = input.next();
  45.  
  46. System.out.println("password: ");
  47. password = input.next();
  48.  
  49. //users check = new users(username, password);
  50.  
  51. if(username.equals(username) && password.equals(password))
  52. System.out.println("You are logged in");
  53.  
  54.  
  55.  
  56. }
  57.  
  58. }
  59.  
  60. import java.util.Scanner;
  61.  
  62. public class LoginMain {
  63.  
  64. public static void main(String[] args) {
  65.  
  66. String Username;
  67. String Password;
  68.  
  69. Password = "123";
  70. Username = "wisdom";
  71.  
  72. Scanner input1 = new Scanner(System.in);
  73. System.out.println("Enter Username : ");
  74. String username = input1.next();
  75.  
  76. Scanner input2 = new Scanner(System.in);
  77. System.out.println("Enter Password : ");
  78. String password = input2.next();
  79.  
  80. if (username.equals(Username) && password.equals(Password)) {
  81.  
  82. System.out.println("Access Granted! Welcome!");
  83. }
  84.  
  85. else if (username.equals(Username)) {
  86. System.out.println("Invalid Password!");
  87. } else if (password.equals(Password)) {
  88. System.out.println("Invalid Username!");
  89. } else {
  90. System.out.println("Invalid Username & Password!");
  91. }
  92.  
  93. }
  94.  
  95. }
  96.  
  97. String user;
  98. String pass;
  99.  
  100. Scanner scan = new Scanner(new File("File.txt"));
  101.  
  102. while(scan.hasNext){ //While the file still has more lines remaining
  103. if(scan.nextLine() == user){
  104. if(scan.nextLine == pass){
  105. lblDisplay.setText("Credentials Accepted.");
  106. }
  107. else{
  108. lblDisplay.setText("Please try again.");
  109. }
  110. }
  111. }
  112.  
  113. import java.<span class="q39pbqr9" id="q39pbqr9_9">net</span>.*;
  114. import java.io.*;
  115.  
  116. <span class="q39pbqr9" id="q39pbqr9_1">public class</span> A
  117. {
  118. static String user = "user";
  119. static String pass = "pass";
  120. static String param_user = "username";
  121. static String param_pass = "password";
  122. static String content = "";
  123. static String action = "action_url";
  124. static String urlName = "url_name";
  125. public static void main(String[] args)
  126. {
  127. try
  128. {
  129. user = URLEncoder.encode(user, "UTF-8");
  130. pass = URLEncoder.encode(pass, "UTF-8");
  131. content = "action=" + action +"&" + param_user +"=" + user + "&" + param_pass + "=" + pass;
  132. URL url = new URL(urlName);
  133. HttpURLConnection urlConnection = (HttpURLConnection)(url.openConnection());
  134. urlConnection.setDoInput(true);
  135. urlConnection.setDoOutput(true);
  136. urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  137. urlConnection.setRequestMethod("POST");
  138. DataOutputStream dataOutputStream = new DataOutputStream(urlConnection.getOutputStream());
  139. dataOutputStream.writeBytes(content);
  140. dataOutputStream.flush();
  141. dataOutputStream.close();
  142.  
  143. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  144. String responeLine;
  145. StringBuilder response = new StringBuilder();
  146. while ((responeLine = bufferedReader.readLine()) != null)
  147. {
  148. response.append(responeLine);
  149. }
  150. System.out.println(response);
  151. }catch(Exception ex){ex.printStackTrace();}
  152. }
Add Comment
Please, Sign In to add comment