From 43865930f8580f6fe97ea9f54686a1b805358a6d Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Fri, 16 Apr 2021 12:58:44 -0500 Subject: Get started on DB work, still needs much work --- csci4131/hw6/strap012_hw6/dbio.js | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 csci4131/hw6/strap012_hw6/dbio.js (limited to 'csci4131/hw6/strap012_hw6/dbio.js') diff --git a/csci4131/hw6/strap012_hw6/dbio.js b/csci4131/hw6/strap012_hw6/dbio.js new file mode 100644 index 0000000..538fa5a --- /dev/null +++ b/csci4131/hw6/strap012_hw6/dbio.js @@ -0,0 +1,71 @@ +var mysql = require("mysql"); +var bcrypt = require("bcrypt"); + +var connection = mysql.createConnection({ + host: "cse-mysql-classes-01.cse.umn.edu", + user: "C4131S21U83", + password: "6919", + database: "C4131S21U83", + port: 3306 +}); + +connection.connect(function(err) { + if (err) { + throw err; + }; + console.log("Connected to MYSQL database!"); +}); + +function passcheck(user,pass) { + let ret = ''; + connection.query('SELECT * FROM tbl_accounts', function(err,rows,fields) { + + if (err) throw err; + if (rows.length == 0) { + console.log("There are no entries in the accounts field!"); + } else { + for (var i = 0 ; i < rows.length; i++) { + if (rows[i].acc_login.localeCompare(user) === 0) { + if (bcrypt.compareSync(pass, rows[i].acc_password)) { + ret += rows[i]; + } + } + } + } + }); + return ret; +} + +function getContacts() { + let conTab = [] + connection.query('SELECT * FROM tbl_contacts', function(err,rows,fields) { + for (let i=0; i