<commit_before>var express = require('express');
var MongoClient = require('mongodb').MongoClient;
var router = express.Router();
var userSchema = require('../models/userSchema');
var connectionString = "mongodb://dishant:<EMAIL>:53196/coursegame";
var ObjectId = require('mongodb').ObjectID;
var crypto = require('crypto');
var algorithm = 'aes-256-ctr';

// localhost:3000/users
router.get('/', function(req, res, next) {
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      collection.find().toArray(function(err, users) {
        if (err) {
    		  res.json({"Status":false,"Result":err});
        }
        else {
          res.send({"Status":true,"Result":users});
        }
      });
    }
  });
});

// localhost:3000/users/getById/:id
router.get('/getById/:id',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      var id = req.params.id;

      collection.findOne({"_id": new ObjectId(id)}, function(err, user) {
        if (err) {
    		  res.json({"Status":false,"Result":err});
        }
        else {
          res.send({"Status":true,"Result":user});
        }
      });
    }
  });
});


// localhost:3000/users/login
router.post('/encrypt',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      var password = req.body.password;

      function encrypt(text){
        var cipher = crypto.createCipher(algorithm,password)
        var crypted = cipher.update(text,'utf8','hex')
        crypted += cipher.final('hex');
        console.log(crypted);
        return crypted;
      }

      function decrypt(text){
        var decipher = crypto.createDecipher(algorithm,password)
        var dec = decipher.update(text,'hex','utf8')
        dec += decipher.final('utf8');
        return dec;
      }

      var encrypted_password = encrypt(password);
      // outputs hello world
      console.log(decrypt(encrypted_password));
    }
  });
});


// localhost:3000/users/login
router.post('/login',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');<commit_msg>encryption and decryption of password<commit_after>var express = require('express');
var MongoClient = require('mongodb').MongoClient;
var router = express.Router();
var userSchema = require('../models/userSchema');
var connectionString = "mongodb://dishant:<EMAIL>:53196/coursegame";
var ObjectId = require('mongodb').ObjectID;
var crypto = require('crypto');
var algorithm = 'aes-256-ctr';

// localhost:3000/users
router.get('/', function(req, res, next) {
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      collection.find().toArray(function(err, users) {
        if (err) {
    		  res.json({"Status":false,"Result":err});
        }
        else {
          res.send({"Status":true,"Result":users});
        }
      });
    }
  });
});

// localhost:3000/users/getById/:id
router.get('/getById/:id',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      var id = req.params.id;

      collection.findOne({"_id": new ObjectId(id)}, function(err, user) {
        if (err) {
    		  res.json({"Status":false,"Result":err});
        }
        else {
          res.send({"Status":true,"Result":user});
        }
      });
    }
  });
});


// localhost:3000/users/login
router.post('/encrypt',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
      var password = req.body.password;

      function encrypt(text){
        var cipher = crypto.createCipher(algorithm,password)
        var crypted = cipher.update(text,'utf8','hex')
        crypted += cipher.final('hex');
        console.log(crypted);
        return crypted;
      }

      function decrypt(text){
        var decipher = crypto.createDecipher(algorithm,password)
        var dec = decipher.update(text,'hex','utf8')
        dec += decipher.final('utf8');
        return dec;
      }

      var encrypted_password = encrypt(password);
      // outputs hello world
      console.log(decrypt(encrypted_password));
      res.send({"Actual Password": password , "Cypher Text" : encrypted_password});
    }
  });
});


// localhost:3000/users/login
router.post('/login',function(req, res, next){
  MongoClient.connect(connectionString, function(err, db) {
    if(!err) {
      var collection = db.collection('User');
{'fraction_non_alphanumeric': 0.16785117056856189, 'fraction_numerical': 0.0112876254180602, 'mean_word_length': 3.1037735849056602, 'pattern_counts': {'":': 19, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6294546', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1442, 'n_words': 257}