Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
เก็บรหัสผ่านยังไงดี 2017
Search
Manatsawin Hanmongkolchai
March 11, 2017
Programming
0
560
เก็บรหัสผ่านยังไงดี 2017
YWC Programmer Meetup #4
Manatsawin Hanmongkolchai
March 11, 2017
Tweet
Share
More Decks by Manatsawin Hanmongkolchai
See All by Manatsawin Hanmongkolchai
Nix: Declarative OS
whs
0
77
gRPC load balancing with xDS
whs
0
940
ArgoCD
whs
0
420
Writing Babel Plugin
whs
0
180
What's new in Cloud Next 2019
whs
0
290
A Date with gRPC
whs
1
1.4k
ตีแผ่ Microservice ด้วย Tracing
whs
0
360
Next Generation Smart Home
whs
0
960
Istio and the Service Mesh Architecture
whs
3
1k
Other Decks in Programming
See All in Programming
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
820
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
340
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
97
34k
dbt民主化とLLMによる開発ブースト ~ AI Readyな分析サイクルを目指して ~
yoshyum
3
1.1k
NPOでのDevinの活用
codeforeveryone
0
870
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
250
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
20250708_JAWS_opscdk
takuyay0ne
2
120
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
200
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
3
480
テスト駆動Kaggle
isax1015
1
510
ISUCON研修おかわり会 講義スライド
arfes0e2b3c
1
460
Featured
See All Featured
Navigating Team Friction
lara
187
15k
A Tale of Four Properties
chriscoyier
160
23k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Raft: Consensus for Rubyists
vanstee
140
7k
Designing for humans not robots
tammielis
253
25k
Facilitating Awesome Meetings
lara
54
6.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Adopting Sorbet at Scale
ufuk
77
9.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Embracing the Ebb and Flow
colly
86
4.7k
Transcript
เก็บรหัสผานยังไงดี 2017 YWC Programmer Meetup
คั่นเวลา • ขอรหัสผานหนอย • 6 ตัว อักษรอังกฤษ ตัวเลข • เดี๋ยวจะทําอะไรใหดู
• ไมตองใสรหัสจริงมานะ • https://madoka.whs.in.th/pwcrack.html ◦ HTTPS ดวย!!
Who? • Manatsawin Hanmongkolchai (@awkwin) • ถาไมไดกดรับเฟรนก็สงขอความมาถามไดไมกัด • แตถาเขียนโคด insecure
นี่กัด
Why? • ทํา Freelance มาหลาย project • ทุก project ที่ตองไปยุง
code เดิมมีชองโหวพื้นๆ หมด ◦ SQL Injection ◦ Insecure Password Hashing • ถาใหพูดทุกประเด็นคงไดเปนชั่วโมง
ขออาง • "ใชคนเดียว ไมเปนไรหรอก" • "เดี๋ยวคอยแกก็ได"
There are two primary causes for the unintentional creation of
insecure web applications, regardless of the language being used: 1. A lack of knowledge about security 2. Bad development habits — ParagonIE
เก็บรหัสผานยังไงดี? • สมัยผมหัดเขียนเว็บเคาใช MD5 $hashed = md5($_POST['password']);
อยาใช MD5 • SHA1 จาย 5 แสนเหรียญ collision ได •
แต MD5 รันไวสักวันสองวันก็ collision ได
เก็บรหัสผานยังไงดี? • แลวเคาก็วา SHA1 $hashed = sha1($_POST['password']);
อยาใช SHA1 • มี harddisk เหลือ ทําตาราง SHA1 (Rainbow Table)
ไวก็ crack SHA1 ไดในพริบตา
เก็บรหัสผานยังไงดี? • แลวเคาก็วาใส salt สิ จะไดปลอดภัย $salt = uniqid(); $hashed
= sha1($_POST['password'] . $salt);
ยินดีตอนรับสูยุคของ Cloud computing • เมื่อกี้ขอรหัสผาน ใสกันหรือยัง • ถาพรอมแลว ลุย!
ยินดีตอนรับสูยุคของ Cloud computing • Google Cloud เชา K80 ชั่วโมงละ 30
บาทเทานั้น!!! • งัด MD5 ได 4 พันลานครั้งตอวินาที • งัด SHA256 ได 642.1 ลานครั้งตอวินาที ◦ = รหัส 8 ตัว เสร็จใน 2 นาที • เชาไดถึง 8 ใบตอเครื่อง !!
แลวเอาไงดี???? • ใช Algorithm "ชา" (>100ms) มีการดจอก็งัดไมทันหรอก ◦ Argon2 ◦
bcrypt ◦ scrypt ◦ PBKDF2 (iPhone ใชอยู)
PHP • PHP 5.5+ มี password hash function มาใหแลว ชวยใชหนอยเถอะ
• $hash = password_hash($_POST['password'] PASSWORD_DEFAULT); • แลว Salt? มันจัดการใหหมดแลวไมตองไปยุง • (ตอนนี้) ใช algorithm bcrypt
PHP • เวลาเช็ครหัสผานทําแบบนี้ • if(!password_verify($_POST['password'], $db_password)){ die('Wrong!'); } if(password_needs_rehash($db_password, PASSWORD_DEFAULT)){
$db_password = password_hash($_POST['password'] PASSWORD_DEFAULT); } • password_verify จะเทียบรหัสผานโดยไมโดน timing attack • password_needs_rehash จะเช็ควารหัสใช algorithm ลาสุดหรือเปลา ถาไมใชก็ upgrade ได (ในกรณีที่ในอนาคต PHP เปลี่ยน default algorithm)
PHP • ถาไมมี PHP5.5? • https://github.com/ircmaxell/password_compat • API เดียวกับเมื่อกี้ จบปง
PHP • ถาไมมี PHP5.3.7??? • ไมยอมอัพเกรดขนาดนั้นก็สมควรโดน hack
ใช Framework เถอะ • งงมั้ย? • Security งายนิดเดียว แคใช Framework
◦ Django (Python) ลง Argon2/Bcrypt เพิ่มได (อานใน Docs) หรือ default จะใช PBKDF2 ◦ อยาเขียนสิ่งที่ framework มันมีใหอยูแลว
Paragonie Blog • เขียนสนุก เขาใจงาย สําหรับคนเขียน PHP • https://paragonie.com/blog/category/security-engineering
จบ ถามไดไมกัด