Guest User

Untitled

a guest
Dec 29th, 2017
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. package com.application.Database;
  2.  
  3. import com.mongodb.*;
  4. import javafx.scene.control.PasswordField;
  5. import javafx.scene.control.TextField;
  6.  
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.logging.Level;
  11. import java.util.logging.LogManager;
  12. import java.util.logging.Logger;
  13.  
  14. import static jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java;
  15.  
  16. public class DBEmployees {
  17. ppublic static boolean authenticate(String username, String password){
  18. boolean flag;
  19. BasicDBObject andQuery = new BasicDBObject();
  20. List<BasicDBObject> obj = new ArrayList<>();
  21. obj.add(new BasicDBObject("email", username));
  22. obj.add(new BasicDBObject("password", password));
  23. andQuery.put("$and", obj);
  24. DBCursor cursor = collection.find(andQuery);
  25. ArrayList<BasicDBObject> x = new ArrayList<>();
  26. while (cursor.hasNext()) {
  27. x.add((BasicDBObject) cursor.next());
  28. cursor.next();
  29. } if(x.size()==1){
  30. flag = true;
  31. }
  32. else {
  33. flag = false;
  34. }
  35. return flag;
  36. }
  37.  
  38.  
  39. final static Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME);
  40.  
  41.  
  42. private static MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
  43.  
  44. private static DB db = mongoClient.getDB("mydb");
  45. private static DBCollection collection = db.getCollection("Employees");
  46.  
  47. public static void main(String[] args) {
  48.  
  49. globalLogger.setLevel(java.util.logging.Level.OFF);
  50.  
  51. BasicDBObject employee1 = new BasicDBObject("name","Damith Asanka")
  52. .append("age","34")
  53. .append("email","damith.a@ugnip.ac.lk")
  54. .append("staff type","specific")
  55. .append("password","123456789B")
  56. .append("space type","office_1")
  57. .append("building number","2");
  58. collection.insert(employee1);
  59. BasicDBObject employee2 = new BasicDBObject("name","Yureni Noshika")
  60. .append("age","18")
  61. .append("email","yureni.n@ugnip.ac.lk")
  62. .append("staff type","authentic")
  63. .append("password","1239256789A")
  64. .append("space type","studio_3")
  65. .append("building number","1");
  66. collection.insert(employee2);
  67. BasicDBObject employee3 = new BasicDBObject("name","Niroshan Dickwella")
  68. .append("age","25")
  69. .append("email","niroshan.d@ugnip.ac.lk")
  70. .append("staff type","specific")
  71. .append("password","123456XyZa")
  72. .append("space type","office_2")
  73. .append("building number","2");
  74. collection.insert(employee3);
  75. BasicDBObject employee4 = new BasicDBObject("name","Thumindu Dodantenna")
  76. .append("age","19")
  77. .append("email","thumindu.d@ugnip.ac.lk")
  78. .append("staff type","specific")
  79. .append("password","456dm2934")
  80. .append("space type","office_6")
  81. .append("building number","1");
  82. collection.insert(employee4);
  83. BasicDBObject employee5 = new BasicDBObject("name","Kalana Jayanath")
  84. .append("age","19")
  85. .append("email","kalana.j@ugnip.ac.lk")
  86. .append("staff type","specific")
  87. .append("password","456d11112934")
  88. .append("space type","office_4")
  89. .append("building number","1");
  90. collection.insert(employee5);
  91. }
  92. }
  93.  
  94. package com.applicationLoginInterface;
  95.  
  96.  
  97. import javafx.fxml.FXML;
  98.  
  99. import javafx.scene.control.PasswordField;
  100. import javafx.scene.control.TextField;
  101.  
  102. import com.application.Database.*;
  103.  
  104.  
  105. import java.io.IOException;
  106.  
  107.  
  108. public class ControllerLogin {
  109.  
  110.  
  111. @FXML private PasswordField loginPassword;
  112. @FXML private TextField loginID;
  113.  
  114.  
  115. public static void main(String[] args){
  116.  
  117. }
  118.  
  119. @FXML private void loginBtnClicked() throws IOException {
  120.  
  121. String username = loginID.getText();
  122. String password = loginPassword.getText();
  123. if(DBEmployees.authenticate(username,password)){
  124. System.out.println("Success");
  125. }
  126. else {
  127. System.out.println("Incorrect login credentials");
  128. }
  129.  
  130. }
  131. }
  132.  
  133. ...
  134. obj.add(new BasicDBObject("email", username.getText()));
  135. obj.add(new BasicDBObject("password", password.getText()));
  136. ...
Add Comment
Please, Sign In to add comment