{"id":861,"date":"2024-08-28T13:18:27","date_gmt":"2024-08-28T13:18:27","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=861"},"modified":"2024-09-02T07:07:37","modified_gmt":"2024-09-02T07:07:37","slug":"nodejs-encrypt-password","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/08\/28\/nodejs-encrypt-password\/","title":{"rendered":"[nodejs]\ube44\ubc00\ubc88\ud638 \uc554\ud638\ud654\ud558\uae30 \/ Encrypt password"},"content":{"rendered":"\n<p>\ud68c\uc6d0 \uac00\uc785\ub41c \uc0ac\uc6a9\uc790\uc758  \ube44\ubc00\ubc88\ud638\uac00 \uc758\ub3c4\uce58 \uc54a\uac8c \ub178\ucd9c\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4<br>Passwords of registered users may be exposed unintentionally..<\/p>\n\n\n\n<p>\uadf8\ub798\uc11c \uc0ac\uc6a9\uc790\uc758 \uac1c\uc778 \uc815\ubcf4\uac00 \ud574\ud0b9\ub418\uac70\ub098 \uc545\uc6a9\ub418\ub294 \uac83\uc744 \ubc29\uc9c0\ud558\uae30 \uc704\ud574\uc11c \ube44\ubc00\ubc88\ud638\ub97c \uc554\ud638\ud654 \uc2dc\ud0a4\ub294\uac8c \uc911\uc694\ud569\ub2c8\ub2e4.<br>Therefore, it is important to encrypt passwords to prevent hacking and misuse of user passwords.<\/p>\n\n\n\n<p>\uc544\ub798\ub294 bcrpt\ubaa8\ub4c8\uc744 \uc0ac\uc6a9\ud574\uc11c \uc0ac\uc6a9\uc790\uc758 \ube44\ubc00\ubc88\ud638\ub97c \uc554\ud638\ud654 \ud558\ub294 \ubc29\ubc95\uc785\ub2c8\ub2e4.<br>Below is how to encrypt your password.<\/p>\n\n\n\n<p>\uc774\uc804\uc5d0 \ub2e4\ub8ec \ub0b4\uc6a9\uc740 \uc544\ub798\uc758 \uc774\uc804 \ud3ec\uc2a4\ud2b8\ub97c \ucc38\uc870\ud558\uc138\uc694<br>If you would like to check more details, please refer to the previous post.<\/p>\n\n\n\n<p>previous post\uc774\uc804\ud3ec\uc2a4\ud2b8 <br><a rel=\"noreferrer noopener\" href=\"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/08\/27\/nodejs-simple-create-a-simple-membership-registration-page\/\" data-type=\"URL\" data-id=\"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2024\/08\/27\/nodejs-simple-create-a-simple-membership-registration-page\/\" target=\"_blank\">\uac04\ub2e8\ud55c \ud68c\uc6d0\uac00\uc785 \ud398\uc774\uc9c0 \ub9cc\ub4e4\uae30 \/ Simple Create a simple membership registration page<\/a><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>bcrypt\ubaa8\ub4c8\uc124\uce58(bcrypt module install)<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"301\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/bcrypt.png\" alt=\"\" class=\"wp-image-862\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/bcrypt.png 962w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/bcrypt-300x94.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/bcrypt-768x240.png 768w\" sizes=\"auto, (max-width: 962px) 100vw, 962px\" \/><\/figure>\n\n\n\n<p>-\ubaa8\ub4c8\uc124\uce58\ud655\uc778(Check module installation)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"361\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/package_json-1.png\" alt=\"\" class=\"wp-image-909\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/package_json-1.png 714w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/package_json-1-300x152.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/figure>\n\n\n\n<p><strong>2.\ubaa8\ub4c8 \ud638\ucd9c\ud558\uae30(Importing module)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"275\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/importModule.png\" alt=\"\" class=\"wp-image-869\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/importModule.png 571w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/importModule-300x144.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure>\n\n\n\n<p><strong>3.\ud328\uc2a4\uc6cc\ub4dc \uc554\ud638\ud654\ud558\uae30(Encrypt passworrd)<\/strong><\/p>\n\n\n\n<p>-bcrypt.hashSync(postPassword,10), \uc774 \ubd80\ubd84\uc774 \uc0ac\uc6a9\uc790 \ube44\ubc00\ubc88\ud638(postPassword)\ub97c \uc554\ud638\ud654 \uc2dc\ud0a4\ub294 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>bcrypt.hashSync(postPassword,10), This is the part that encrypts the usres password.<\/p>\n\n\n\n<p>-10\uc740 \uc554\ud638\ud654 \ubaa8\ub4c8\uc218\ud589 \ud69f\uc218 \uc785\ub2c8\ub2e4.<br>10 is the number of times the encryption module is executed.<\/p>\n\n\n\n<p>-\uae30\ubcf8\uc801\uc73c\ub85c \uc554\ud638\ud574\ub3c5\uc774 \ubd88\uac00\ub2a5\ud558\uc9c0\ub9cc \uc554\ud638\ud654 \ubaa8\ub4c8 \uc218\ud589 \ud69f\uc218\uac00 \ub108\ubb34 \uc801\uc73c\uba74 \uc554\ud638\ud654 \ud328\ud134\uc744 \ud30c\uc545\ud558\ub294 \uc0ac\ub78c\uc774 \uc788\ub2e4\uace0 \ud569\ub2c8\ub2e4.<br>It is said that decryption is basically impossible, but if the encryption module is performed too few times, there are people who can figure out the encryption pattern.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"795\" height=\"310\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/tryCatch.png\" alt=\"\" class=\"wp-image-863\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/tryCatch.png 795w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/tryCatch-300x117.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/tryCatch-768x299.png 768w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><\/figure>\n\n\n\n<p><strong>4.\ube0c\ub77c\uc6b0\uc800\ud14c\uc2a4\ud2b8(browser test)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"539\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/memberinput.png\" alt=\"\" class=\"wp-image-911\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/memberinput.png 780w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/memberinput-300x207.png 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/memberinput-768x531.png 768w\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"260\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/join-1.png\" alt=\"\" class=\"wp-image-872\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/join-1.png 644w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/join-1-300x121.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/figure>\n\n\n\n<p><strong>5.Mysql Database<\/strong><br>-\ube0c\ub77c\uc6b0\uc800\uc640 \ub3d9\uc77c\ud55c \ud328\uc2a4\uc6cc\ub4dc\uac00 \uc800\uc7a5\ub41c \uac83\uc744 \ud655\uc778 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can check that the same password as your browser is saved.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"213\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/mysql-2.png\" alt=\"\" class=\"wp-image-874\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/mysql-2.png 769w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2024\/08\/mysql-2-300x83.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/figure>\n\n\n\n<p><strong>6.server.js\uc804\uccb4\ucf54\ub4dc(server.js full code)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n\/\/server.js --&gt; Commonjs type\nconst { createServer } = require('http');\nconst ejs = require('ejs'); \/\/ejs\nconst express = require('express'); \/\/express\nconst path = require('path'); \/\/path\nconst mysql = require('mysql2'); \/\/ mysql\nvar bodyParser = require('body-parser'); \/\/ post method \n<strong>const bcrypt = require('bcrypt');  \/\/ password encrypt<\/strong>\n\nconst app = express();\nconst server = createServer(app);\n\n\/\/ ejs settings\n\/\/-----------------------------------------------\napp.set('view engine','ejs');\napp.set('views','.\/public');\n\n\/\/bodyParser\napp.use(bodyParser.urlencoded({ extended: false }));\n\n\/\/ Serve static files from the 'public' directory\napp.use(express.static(path.join(__dirname, \"public\")));\n\n\/\/-----------------------------------------------\n\/\/ mysql db information\nconst dbname = \"your_db_name\";\nconst hostname = \"your_host_name\";\nconst dbuser = \"your_db_user\";\nconst dbpassword = \"your_db_password\";\n\n\/\/ module import\nconst {\n  userInsert,\n} = require(\".\/mysqldb\");\n\n\n\n\/*---------------------------------------------------------------------------\n  member\n---------------------------------------------------------------------------*\/\n\n\/\/ memberInput.ejs \ubd88\ub7ec\uc624\uae30 \/ Load login.ejs\napp.get(\"\/memberinput\", (req, res) =&gt; {\n\n  res.render('memberInput');\n      \n});\n\n\/\/ \ud68c\uc6d0\uac00\uc785 \/ join the membership\napp.post(\"\/join\", async(req, res) =&gt; {\n\n  \/\/ post method\n  var userid = req.body.userid;\n  var username = req.body.username;\n  var postPassword = req.body.password;\n\n  const connection = mysql.createConnection({\n    host     : hostname,\n    user     : dbuser,\n    password : dbpassword,\n    database : dbname\n  });\n  \n \n  try{\n\n<strong>    const encryptedPassowrd = bcrypt.hashSync(postPassword, 10) \/\/password encrypt<\/strong>\n    \n    \/\/ db insert\n    await userInsert(hostname, dbuser, dbpassword, dbname, userid,<strong>encryptedPassowrd<\/strong>,username)\n\n    \/\/ load test.ejs\n    res.render('test',{message:userid,<strong>message2:encryptedPassowrd<\/strong>,message3:username});\n\n  }catch(error){\n    \/\/ print error message\n    console.error('Error fetching data:', error);\n    res.status(500).send('Internal Server Error');\n\n  }\n\n});\n\n\n\/\/ Start the server\nconst PORT = process.env.PORT || 3000;\nserver.listen(PORT, () =&gt; {\n  console.log(`Server is running on port ${PORT}`);\n});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud68c\uc6d0 \uac00\uc785\ub41c \uc0ac\uc6a9\uc790\uc758 \ube44\ubc00\ubc88\ud638\uac00 \uc758\ub3c4\uce58 \uc54a\uac8c \ub178\ucd9c\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4Passwords of registered users may be exposed unintentionally.. \uadf8\ub798\uc11c \uc0ac\uc6a9\uc790\uc758 \uac1c\uc778 \uc815\ubcf4\uac00 \ud574\ud0b9\ub418\uac70\ub098 \uc545\uc6a9\ub418\ub294 \uac83\uc744 \ubc29\uc9c0\ud558\uae30 \uc704\ud574\uc11c \ube44\ubc00\ubc88\ud638\ub97c \uc554\ud638\ud654 \uc2dc\ud0a4\ub294\uac8c \uc911\uc694\ud569\ub2c8\ub2e4.Therefore, it is important to encrypt passwords to prevent hacking and misuse of user passwords. \uc544\ub798\ub294 bcrpt\ubaa8\ub4c8\uc744 \uc0ac\uc6a9\ud574\uc11c \uc0ac\uc6a9\uc790\uc758 \ube44\ubc00\ubc88\ud638\ub97c \uc554\ud638\ud654 \ud558\ub294 \ubc29\ubc95\uc785\ub2c8\ub2e4.Below is how to encrypt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-861","post","type-post","status-publish","format-standard","hentry","category-nodejs","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=861"}],"version-history":[{"count":21,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":912,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/861\/revisions\/912"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}