{"id":380,"date":"2026-05-17T09:00:00","date_gmt":"2026-05-17T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/"},"modified":"2026-10-10T21:21:29","modified_gmt":"2026-10-10T15:51:29","slug":"go-password-hashing-bcrypt","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/","title":{"rendered":"Go Password Hashing with bcrypt Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go password hashing with bcrypt is the safe, standard way to store user passwords in a Go backend. In this post, you will learn why you must never store plain passwords and how hashing and salting work. Also, you will see how bcrypt&#8217;s cost setting slows down attackers. Then we will build register and login logic that checks passwords correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In fact, this lesson prepares the ground for login in our API. So it builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/\">the Go REST API tutorial<\/a> and the error checks from <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">Go error handling for beginners<\/a>. Then, next time, we will add JWT tokens on top of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Password Hashing?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, hashing turns a password into a fixed-length string, and nobody can turn that string back into the password. When a user logs in, you hash what they typed and compare it with the stored hash. So you never need to keep the real password anywhere.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a fingerprint. Your fingerprint proves who you are. Still, nobody can rebuild your whole hand from it. Similarly, a password hash proves the user knows the password, but it does not reveal the password itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In particular, bcrypt is a password hashing function designed to be slow on purpose. Also, in Go it lives in the <code>golang.org\/x\/crypto\/bcrypt<\/code> package, which the Go team maintains.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Password Hashing Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Databases leak more often than anyone likes. So if your users table holds plain passwords, every account is exposed at once. Worse, many people reuse passwords, so attackers try them on email and bank sites too. Specifically, here is what proper Go password hashing protects against.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Database leaks<\/strong>: attackers get hashes, not passwords, so they must still crack each one.<\/li>\n\n\n\n<li><strong>Insider access<\/strong>: even admins cannot read users&#8217; passwords.<\/li>\n\n\n\n<li><strong>Rainbow tables<\/strong>: a random salt per user makes precomputed lookup tables useless.<\/li>\n\n\n\n<li><strong>Brute force<\/strong>: a slow hash means each guess costs real time and money.<\/li>\n\n\n\n<li><strong>Reused passwords<\/strong>: one leaked site does not hand over the user&#8217;s other accounts.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Go password hashing turns a disaster into a manageable incident.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Password Hashing with bcrypt Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First, bcrypt creates a random salt, which is a unique random value for this one password. After that, it mixes the salt and the password through a deliberately expensive process. Then it repeats that work many times, based on the cost setting. Finally, it stores the algorithm version, the cost, the salt and the hash together in one string.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-1024x640.png\" alt=\"Go Password Hashing diagram showing password plus salt through bcrypt rounds into a 60 character hash\" class=\"wp-image-367\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">bcrypt combines the password with a fresh random salt, runs 2 to the power of cost rounds, and stores version, cost, salt and hash in one 60-character string.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Because the salt is inside the result, you do not need a separate salt column. Also, two users with the same password get completely different hashes, since their salts differ.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reading a bcrypt Hash<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A bcrypt hash is always 60 characters long and has four parts. So this table breaks down a real example.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>Example<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>Version<\/td><td><code>$2a$<\/code><\/td><td>The bcrypt variant Go produces<\/td><\/tr><tr><td>Cost<\/td><td><code>10$<\/code><\/td><td>2 to the power 10, so 1,024 rounds<\/td><\/tr><tr><td>Salt<\/td><td>first 22 characters after the cost<\/td><td>Random value for this password<\/td><\/tr><tr><td>Hash<\/td><td>last 31 characters<\/td><td>The actual hashed result<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The Cost Factor<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, the cost decides how slow each hash is. In fact, each step up doubles the work. We measured bcrypt on our test machine, so the numbers below show the real effect.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Cost<\/th><th>Time per hash (our machine)<\/th><th>Good for<\/th><\/tr><\/thead><tbody><tr><td>10 (Go default)<\/td><td>about 76 ms<\/td><td>Most web apps today<\/td><\/tr><tr><td>12<\/td><td>about 280 ms<\/td><td>Higher security needs<\/td><\/tr><tr><td>14<\/td><td>about 1.1 seconds<\/td><td>Too slow for busy login pages<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So pick a cost that keeps login under a few hundred milliseconds on your servers. Then raise it over the years as hardware gets faster.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Password Hashing: bcrypt vs SHA-256 vs Argon2id<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">However, not every hash function is safe for passwords. So the table below compares three common choices.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>bcrypt<\/th><th>SHA-256<\/th><th>Argon2id<\/th><\/tr><\/thead><tbody><tr><td>Built for passwords<\/td><td>Yes<\/td><td>No, built for speed<\/td><td>Yes<\/td><\/tr><tr><td>Built-in salt<\/td><td>Yes<\/td><td>No, you add it<\/td><td>Yes<\/td><\/tr><tr><td>Adjustable cost<\/td><td>Yes, one number<\/td><td>No<\/td><td>Yes, time and memory<\/td><\/tr><tr><td>Resists GPU cracking<\/td><td>Good<\/td><td>Poor<\/td><td>Very good<\/td><\/tr><tr><td>Max password length<\/td><td>72 bytes<\/td><td>Any<\/td><td>Any<\/td><\/tr><tr><td>Ease of use in Go<\/td><td>Very easy<\/td><td>Easy, but wrong tool<\/td><td>Easy with <code>x\/crypto\/argon2<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-1024x640.png\" alt=\"Go Password Hashing diagram comparing fast SHA-256 guesses with slow bcrypt guesses\" class=\"wp-image-368\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A fast hash like SHA-256 lets attackers try billions of guesses, while bcrypt&#8217;s cost makes every guess slow.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use bcrypt or Argon2id for passwords, and never a plain fast hash like SHA-256. Overall, bcrypt is the simplest safe choice for most Go apps.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-On: Register and Login with bcrypt<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s write the Go password hashing part of a user service. First, add the package with <code>go get golang.org\/x\/crypto\/bcrypt<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Hash a Password and Check It<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To begin with, this small program shows the full flow.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"golang.org\/x\/crypto\/bcrypt\"\n)\n\nfunc main() {\n\tpassword := \"secret123\"\n\n\thash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfmt.Println(\"hash:\", string(hash))\n\tfmt.Println(\"length:\", len(hash))\n\n\tcost, _ := bcrypt.Cost(hash)\n\tfmt.Println(\"cost:\", cost)\n\n\terr = bcrypt.CompareHashAndPassword(hash, []byte(\"secret123\"))\n\tfmt.Println(\"correct password:\", err == nil)\n\n\terr = bcrypt.CompareHashAndPassword(hash, []byte(\"wrong-pass\"))\n\tif errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {\n\t\tfmt.Println(\"wrong password rejected\")\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output looks like this. However, your hash will differ on every run, because the salt is random.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hash: $2a$10$7V9YJ9qysnUMHZG8WU325OnFqOZdPXNFjZJQoUVGkxM20Wn9UdiuG\nlength: 60\ncost: 10\ncorrect password: true\nwrong password rejected<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>GenerateFromPassword<\/code> creates the salt and the hash in one call. Meanwhile, <code>CompareHashAndPassword<\/code> reads the cost and salt from the stored hash, so you never pass them yourself.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: A Simple User Store<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After that, we keep users in memory, guarded by a mutex. In a real app, this would be the PostgreSQL table from earlier lessons.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type UserStore struct {\n\tmu    sync.Mutex\n\tusers map[string][]byte \/\/ email -&gt; bcrypt hash\n}\n\nvar ErrEmailTaken = errors.New(\"email already registered\")\nvar ErrBadLogin = errors.New(\"invalid email or password\")\n\nfunc (s *UserStore) Register(email, password string) error {\n\tif len(password) &lt; 8 {\n\t\treturn errors.New(\"password must be at least 8 characters\")\n\t}\n\thash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)\n\tif err != nil {\n\t\treturn err\n\t}\n\ts.mu.Lock()\n\tdefer s.mu.Unlock()\n\tif _, ok := s.users[email]; ok {\n\t\treturn ErrEmailTaken\n\t}\n\ts.users[email] = hash\n\treturn nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that we hash before taking the lock. Since hashing takes about 76 ms, holding the lock during it would block every other user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Login That Leaks Nothing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Also, the login check must not reveal whether an email exists. So it returns the same error for an unknown email and a wrong password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ dummyHash is compared when the email is unknown, so timing stays similar.\nvar dummyHash, _ = bcrypt.GenerateFromPassword([]byte(\"dummy-password\"), bcrypt.DefaultCost)\n\nfunc (s *UserStore) Login(email, password string) error {\n\ts.mu.Lock()\n\thash, ok := s.users[email]\n\ts.mu.Unlock()\n\n\tif !ok {\n\t\tbcrypt.CompareHashAndPassword(dummyHash, []byte(password))\n\t\treturn ErrBadLogin\n\t}\n\tif err := bcrypt.CompareHashAndPassword(hash, []byte(password)); err != nil {\n\t\treturn ErrBadLogin\n\t}\n\treturn nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Why compare against a dummy hash? Without it, an unknown email returns instantly, while a known one takes about 76 ms. Therefore, an attacker could time the replies to learn which emails are registered. In contrast, the dummy comparison makes both paths take similar time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Go Password Hashing in an HTTP Handler<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we expose registration as an API endpoint. The handler decodes JSON, calls <code>Register<\/code> and maps each error to a clear status code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *UserStore) handleRegister(w http.ResponseWriter, r *http.Request) {\n\tvar in struct {\n\t\tEmail    string `json:\"email\"`\n\t\tPassword string `json:\"password\"`\n\t}\n\tif err := json.NewDecoder(r.Body).Decode(&amp;in); err != nil {\n\t\thttp.Error(w, \"invalid JSON\", http.StatusBadRequest)\n\t\treturn\n\t}\n\terr := s.Register(in.Email, in.Password)\n\tswitch {\n\tcase errors.Is(err, ErrEmailTaken):\n\t\thttp.Error(w, err.Error(), http.StatusConflict)\n\tcase err != nil:\n\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\tdefault:\n\t\tw.WriteHeader(http.StatusCreated)\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So a new user gets <code>201 Created<\/code>, and a repeated email gets <code>409 Conflict<\/code>. Meanwhile, a short password gets <code>400 Bad Request<\/code>. Notice that the response never contains the password or the hash. In fact, good Go password hashing code keeps both out of every response and every log line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Upgrade Old Hashes on Login<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Over the years, computers get faster, which weakens old Go password hashing settings. So one day you will raise the cost from 10 to 12. However, existing users still have cost 10 hashes, and you cannot rehash them without their password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The trick is to upgrade at login, because that is the only moment you see the real password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *UserStore) LoginAndUpgrade(email, password string, wantCost int) error {\n\tif err := s.Login(email, password); err != nil {\n\t\treturn err\n\t}\n\ts.mu.Lock()\n\thash := s.users[email]\n\ts.mu.Unlock()\n\n\tif cost, err := bcrypt.Cost(hash); err == nil &amp;&amp; cost &lt; wantCost {\n\t\tnewHash, err := bcrypt.GenerateFromPassword([]byte(password), wantCost)\n\t\tif err == nil {\n\t\t\ts.mu.Lock()\n\t\t\ts.users[email] = newHash\n\t\t\ts.mu.Unlock()\n\t\t}\n\t}\n\treturn nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the normal login check runs. Then <code>bcrypt.Cost<\/code> reads the stored cost from the hash itself. Finally, if it is too low, we save a fresh, stronger hash. As a result, active users move to the new cost quietly, without any password reset.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Password Hashing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Storing plain or encrypted passwords<\/strong>: anyone with the key or the database reads them. Always hash with bcrypt instead.<\/li>\n\n\n\n<li><strong>Using SHA-256 or MD5<\/strong>: these are too fast, so GPUs crack them quickly. Use a password hash.<\/li>\n\n\n\n<li><strong>Comparing two hashes directly<\/strong>: a new hash has a new salt, so it never matches. Instead, use <code>CompareHashAndPassword<\/code>.<\/li>\n\n\n\n<li><strong>Ignoring the 72-byte limit<\/strong>: newer versions return <code>bcrypt: password length exceeds 72 bytes<\/code>. So cap password length in validation.<\/li>\n\n\n\n<li><strong>Different errors for &#8220;no user&#8221; and &#8220;wrong password&#8221;<\/strong>: attackers learn which emails exist. Return one generic error.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Password Hashing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>**Start with <code>bcrypt.DefaultCost<\/code>**, because it balances safety and speed today.<\/li>\n\n\n\n<li><strong>Store the full 60-character hash<\/strong>, since it already contains the salt and cost.<\/li>\n\n\n\n<li><strong>Rehash on login when you raise the cost<\/strong>, so old users move to the stronger setting.<\/li>\n\n\n\n<li><strong>Rate limit login attempts<\/strong>, as slow hashing alone does not stop online guessing.<\/li>\n\n\n\n<li><strong>Never log passwords<\/strong>, even in debug mode, because logs are rarely protected well.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go password hashing, write a function <code>NeedsRehash(hash []byte, want int) bool<\/code>. It should return true when the stored cost is lower than <code>want<\/code>. Then call it after a successful login and save a fresh hash if needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: use <code>bcrypt.Cost(hash)<\/code> to read the stored cost. Then reuse your function inside <code>LoginAndUpgrade<\/code> instead of the inline check.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages explain the package and the reasons behind modern password storage, so read them before going live.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/golang.org\/x\/crypto\/bcrypt\">bcrypt package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/golang.org\/x\/crypto\/argon2\">argon2 package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cheatsheetseries.owasp.org\/cheatsheets\/Password_Storage_Cheat_Sheet.html\">OWASP Password Storage Cheat Sheet<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go password hashing turns passwords into hashes you can check but not reverse.<\/li>\n\n\n\n<li>bcrypt adds a random salt and a slow cost factor to every hash.<\/li>\n\n\n\n<li>Use <code>GenerateFromPassword<\/code> to hash and <code>CompareHashAndPassword<\/code> to check.<\/li>\n\n\n\n<li>The default cost of 10 is a good start; raise it as hardware improves.<\/li>\n\n\n\n<li>Never use fast hashes like SHA-256 for passwords.<\/li>\n\n\n\n<li>Return one generic error so attackers cannot discover registered emails.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">At this point, users can register and prove their password. Next, we will keep them logged in across requests with JWT authentication.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-jwt-authentication\/\">Go JWT Authentication for REST APIs<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go password hashing with bcrypt is the safe, standard way to store user passwords in a Go backend. In this post, you will learn&hellip;<\/p>\n","protected":false},"author":1,"featured_media":366,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,74,23,21],"swapz_series":[],"class_list":["post-380","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-security","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Password Hashing with bcrypt Explained Simply<\/title>\n<meta name=\"description\" content=\"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Password Hashing with bcrypt Explained Simply\" \/>\n<meta property=\"og:description\" content=\"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-17T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:51:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Password Hashing with bcrypt Explained\",\"datePublished\":\"2026-05-17T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/\"},\"wordCount\":1483,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-password-hashing-bcrypt-featured.png\",\"keywords\":[\"Go Lang\",\"Go Security\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/\",\"name\":\"Go Password Hashing with bcrypt Explained Simply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-password-hashing-bcrypt-featured.png\",\"datePublished\":\"2026-05-17T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:29+00:00\",\"description\":\"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-password-hashing-bcrypt-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-password-hashing-bcrypt-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Password Hashing featured image: cards for the salt, the cost factor and login checks\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-password-hashing-bcrypt\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Password Hashing with bcrypt Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Password Hashing with bcrypt Explained Simply","description":"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/","og_locale":"en_US","og_type":"article","og_title":"Go Password Hashing with bcrypt Explained Simply","og_description":"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.","og_url":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-17T03:30:00+00:00","article_modified_time":"2026-10-10T15:51:29+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Password Hashing with bcrypt Explained","datePublished":"2026-05-17T03:30:00+00:00","dateModified":"2026-10-10T15:51:29+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/"},"wordCount":1483,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png","keywords":["Go Lang","Go Security","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/","url":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/","name":"Go Password Hashing with bcrypt Explained Simply","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png","datePublished":"2026-05-17T03:30:00+00:00","dateModified":"2026-10-10T15:51:29+00:00","description":"Learn Go password hashing with bcrypt: why plain passwords are dangerous, how salts and cost work, and safe register and login code.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-password-hashing-bcrypt-featured.png","width":2400,"height":1260,"caption":"Go Password Hashing featured image: cards for the salt, the cost factor and login checks"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Password Hashing with bcrypt Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=380"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":390,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/380\/revisions\/390"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/366"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=380"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}