ขออนุญาตตั้งกระทู้ใหม่นะค่ะ

รบกวนปรึกษาแนวคิดหน่อยค่ะ ในการส่ง username + password ไปให้ API วิธีไหนปลอดภัยกว่ากัน
ทั้ง Client และ API เข้าผ่าน protocal https ตามคำแนะนำของกระทู้ก่อนหน้าค่ะ

  1. ส่งไปเป็น Plain text ให้ API
  2. เข้ารหัส Password แล้วส่งไปให้ API แล้วก็ถอดรหัสจะได้ Password แบบ Plain text แล้วเอาไปเช็ค Hash
  3. เข้ารหัส Hash ก่อน แล้วค่อยส่งไปให้ API
    พี่ๆใช่แบบไหนกันค่ะ

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

hash มัน reverse ไม่ได้ แต่สามารถตรวจเปรียบเทียบ (validate) ได้ครับ

client ส่ง hash ไป ส่วน server ก็เก็บค่า hash ไว้ตั้งแต่สร้าง username + password แล้วเอามาเทียบกันครับ

ใน php ใช้ hash_equals เพื่อเทียบครับ

จริงๆ wordpress ก็ใช้วิธีนี้นะ

ผมไม่แน่ใจว่าโค้ดนั่นทำงานที่ฝั่งไหนนะครับ (อ่านผ่านๆ)

ที่นี้เงื่อนไขที่ด้านบนแจ้งผมมาคือเอา password ไปผสม salt และ timestamp ก่อนส่งไปที่ server แต่ว่าจะไม่มีการส่ง salt จาก server ไปยัง client และไม่มีการเก็บ password plain text ด้วย ผมเลยไล่การทำงานไม่ถูกครับ - -"

ปกติการ hash รหัสผ่านจะมี salt ด้วย ซึ่งเป็นส่วนที่ทำให้ความปลอดภัยเพิ่มขึ้นโดยเฉพาะเมื่อฐานข้อมูลหลุดออกไปครับ หากใช้ข้อ 3 ถ้าเราจะให้ client hash รหัสผ่านได้ตรงกับในฐานข้อมูลนั่นหมายถึง client จะต้องรู้ salt ด้วยแล้วจะไม่ปลอดภัยเอา

ข้อ 1, 2 นี่ถ้านับจริงๆ ก็ไม่ใช่ plain text เปลือยๆ เสียทีเดียวครับเพราะมันเข้ารหัสด้วย HTTPS แล้ว แต่เท่าที่ผมลองส่องดู อย่าง blognone เองนี่เวลา login ก็ส่ง user password บน HTTPS ตรงๆ ไม่ได้เข้ารหัสซ้อนอีกชั้นนะครับ

ขอบคุณค่ะ ขอสอบถามเพิ่มนะค่ะ
คือเราทำ hash + salt อยู่แล้ว แต่เราเก็บ salt ไว้ในตารางเดียวกันเลยค่ะ ประมาณนี้

Table User
id, username, password, salt

เขาทำกันแบบนี้หรือป่าวนะ ขอถามเป็นความรู้ค่ะ

แต่ถ้าเก็บแบบนี้ database หลุด salt ก็ไปด้วยแน่เลย หรือว่าเขาจะเก็บแยกกันนะ

ตรงนี้ขอรบกวนท่านอื่นด้วยครับ ผมไม่เคยทำ ? โดยส่วนตัวทุกงานที่มีต้อง auth ผมใช้ Firebase Auth หมดเลย

ปกติจะเก็บบน DB อย่างง่ายแบบนี้

Table User
int id, varchar username, text password_hash

  • client login ก็ส่ง username, password แบบ plain text
  • server รับ username, password แบบ plain text จากนั้นก็ hash(password) แล้วไป where เอาใน db

ใช่ครับ ปกติต้องเป็นแบบนั้นอยู่แล้ว แต่ผมเน้นย้ำกับ จขกท. น่ะครับ เพราะเป็นประเด็นที่ จขกท. กังวล คือเรื่องความปลอดภัยและการเข้ารหัส

จำได้ว่าผมส่งแบบ plain text แต่เพิ่ม OTP และผ่าน https นี่แหละกระมัง

หลังจากนั้นถ้าเข้าระบบสำเร็จก็ได้ access token เข้าไปแทน และให้เปลี่ยน secret key ทุกสามสิบนาที ทั้งที่จริงน่าจะทำ Oauth แต่สติปัญญาผมมันน้อย(ไม่รู้ว่าจบ cs มาได้ยังไง งงจนถึงบัดนี้)

https://security.stackexchange.com/questions/63435/why-use-an-authentication-token-instead-of-the-username-password-per-request

อยากให้ปลอดภัยต้องเริ่มจาก Structure ครับ คือไปตั้ง Domain แล้ว Sign-in ด้วย Domain แล้วทำ OAuth
ถ้าเก็บบน Database ต้องเขียน Code แบบ Code-First อย่าใช้ Stored หรือ ฝัง SQL command select ไว้ใน code แยก hash แยก salt คนละ table วิธีตรวจสอบ password ให้เอา plain text ไป encode ก่อนแล้วค่อยส่งค่าเข้า API ใน API ไม่ต้อง decode password กลับมาเป็น plain text เอา ไอ้ที่ encode เละๆ นั่งแหละ เทียบกับ database แล้วค่อยสร้าง OAuth ตอบกลับไป

tw999 Tue, 07/05/2019 - 18:20

https://security.stackexchange.com/questions/63435/why-use-an-authentication-token-instead-of-the-username-password-per-request