Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김민재] Assignment 2: Express API - 유저 회원가입 하기(암호화) #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion minjae/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ const port = 3000;

const app = express();

const bcrypt = require("bcrypt");
const saltRounds = 12;

/*
const makeHash = async (password, saltRounds) => {
return await bcrypt.hash(password, saltRounds);
};


const getEncryptedPassword = async () => {
const hashedPassword = await makeHash(password, saltRounds);
console.log("다음은 암호화된 비밀번호 입니다: ", hashedPassword);
};


getEncryptedPassword();
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 불필요한 코드 주석을 삭제하여 주세요!~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 주석 부분 삭제했습니다.


const mySqlDataSource = new DataSource({
type: process.env.DB_CONNECTION,
host: process.env.DB_HOST,
Expand All @@ -28,10 +46,16 @@ app.get("/ping", (req, res) => {

app.post("/users", async (req, res) => {
const { id, pwd, name, phone, email, guest_yn } = req.body;
const makeHash = async (pwd, saltRounds) => {
return await bcrypt.hash(pwd, saltRounds);
};
const cryptedpassword = await makeHash(pwd, saltRounds);

console.log(cryptedpassword);

await mySqlDataSource.query(
"INSERT INTO westagram.users (user_id, password, name, phone, email, guest_yn) VALUES (?, ?, ?, ?, ?, ?);",
[id, pwd, name, phone, email, guest_yn]
[id, cryptedpassword, name, phone, email, guest_yn]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 해당 id 값은 회원 가입시, 클라이언트에게 전달되지 않는 것이 아니라, AUTO_INCREMENT에 의해 자동으로 고유값을 설정하는 데이터베이스의 성질을 이용해주시면 좋을 것 같네요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 변수명을 컬럼명과 동일하게 user_id로 변경했습니다.

);
res.status(201).json({ message: "successfully created" });
});
Expand Down
Loading