diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-04-30 08:41:38 -0500 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-04-30 08:41:38 -0500 |
commit | 05c691be64d1356b0a996d1c2a2f5b0286653c85 (patch) | |
tree | dadbde32d1384913fc981982b2c74eef098eeef5 /csci4131/hw7/insert_into_accounts_table.js | |
parent | Add HW5 to git (diff) | |
parent | Add HW6 files (diff) | |
download | homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar.gz homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar.bz2 homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar.lz homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar.xz homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.tar.zst homework-05c691be64d1356b0a996d1c2a2f5b0286653c85.zip |
Merge branch 'master' of github.com:RosstheRoss/TestingFun
Diffstat (limited to '')
-rw-r--r-- | csci4131/hw7/insert_into_accounts_table.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/csci4131/hw7/insert_into_accounts_table.js b/csci4131/hw7/insert_into_accounts_table.js new file mode 100644 index 0000000..3157ce3 --- /dev/null +++ b/csci4131/hw7/insert_into_accounts_table.js @@ -0,0 +1,45 @@ +/* +TO DO: +----- +READ ALL COMMENTS AND REPLACE VALUES ACCORDINGLY +*/ + +const mysql = require("mysql"); +const bcrypt = require('bcrypt'); + +const dbCon = mysql.createConnection({ + host: "cse-mysql-classes-01.cse.umn.edu", + user: "C4131S21U83", // replace with the database user provided to you + password: "6919", // replace with the database password provided to you + database: "C4131S21U83", // replace with the database user provided to you + port: 3306 +}); + +console.log("Attempting database connection"); +dbCon.connect(function (err) { + if (err) { + throw err; + } + + console.log("Connected to database!"); + + const saltRounds = 10; + const myPlaintextPassword = 'tango'; // replace with password chosen by you OR retain the same value + const passwordHash = bcrypt.hashSync(myPlaintextPassword, saltRounds); + + const rowToBeInserted = { + acc_name: 'charlie', // replace with acc_name chosen by you OR retain the same value + acc_login: 'charlie', // replace with acc_login chosen by you OR retain the same value + acc_password: passwordHash + }; + + console.log("Attempting to insert record into tbl_accounts"); + dbCon.query('INSERT tbl_accounts SET ?', rowToBeInserted, function (err, result) { + if (err) { + throw err; + } + console.log("Table record inserted!"); + }); + + dbCon.end(); +}); |