Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.application.Database;
- import com.mongodb.*;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.LogManager;
- import java.util.logging.Logger;
- import static jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java;
- public class DBEmployees {
- ppublic static boolean authenticate(String username, String password){
- boolean flag;
- BasicDBObject andQuery = new BasicDBObject();
- List<BasicDBObject> obj = new ArrayList<>();
- obj.add(new BasicDBObject("email", username));
- obj.add(new BasicDBObject("password", password));
- andQuery.put("$and", obj);
- DBCursor cursor = collection.find(andQuery);
- ArrayList<BasicDBObject> x = new ArrayList<>();
- while (cursor.hasNext()) {
- x.add((BasicDBObject) cursor.next());
- cursor.next();
- } if(x.size()==1){
- flag = true;
- }
- else {
- flag = false;
- }
- return flag;
- }
- final static Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME);
- private static MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
- private static DB db = mongoClient.getDB("mydb");
- private static DBCollection collection = db.getCollection("Employees");
- public static void main(String[] args) {
- globalLogger.setLevel(java.util.logging.Level.OFF);
- BasicDBObject employee1 = new BasicDBObject("name","Damith Asanka")
- .append("age","34")
- .append("email","damith.a@ugnip.ac.lk")
- .append("staff type","specific")
- .append("password","123456789B")
- .append("space type","office_1")
- .append("building number","2");
- collection.insert(employee1);
- BasicDBObject employee2 = new BasicDBObject("name","Yureni Noshika")
- .append("age","18")
- .append("email","yureni.n@ugnip.ac.lk")
- .append("staff type","authentic")
- .append("password","1239256789A")
- .append("space type","studio_3")
- .append("building number","1");
- collection.insert(employee2);
- BasicDBObject employee3 = new BasicDBObject("name","Niroshan Dickwella")
- .append("age","25")
- .append("email","niroshan.d@ugnip.ac.lk")
- .append("staff type","specific")
- .append("password","123456XyZa")
- .append("space type","office_2")
- .append("building number","2");
- collection.insert(employee3);
- BasicDBObject employee4 = new BasicDBObject("name","Thumindu Dodantenna")
- .append("age","19")
- .append("email","thumindu.d@ugnip.ac.lk")
- .append("staff type","specific")
- .append("password","456dm2934")
- .append("space type","office_6")
- .append("building number","1");
- collection.insert(employee4);
- BasicDBObject employee5 = new BasicDBObject("name","Kalana Jayanath")
- .append("age","19")
- .append("email","kalana.j@ugnip.ac.lk")
- .append("staff type","specific")
- .append("password","456d11112934")
- .append("space type","office_4")
- .append("building number","1");
- collection.insert(employee5);
- }
- }
- package com.applicationLoginInterface;
- import javafx.fxml.FXML;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import com.application.Database.*;
- import java.io.IOException;
- public class ControllerLogin {
- @FXML private PasswordField loginPassword;
- @FXML private TextField loginID;
- public static void main(String[] args){
- }
- @FXML private void loginBtnClicked() throws IOException {
- String username = loginID.getText();
- String password = loginPassword.getText();
- if(DBEmployees.authenticate(username,password)){
- System.out.println("Success");
- }
- else {
- System.out.println("Incorrect login credentials");
- }
- }
- }
- ...
- obj.add(new BasicDBObject("email", username.getText()));
- obj.add(new BasicDBObject("password", password.getText()));
- ...
Add Comment
Please, Sign In to add comment