• 0

Web server salt storage


Question

There is just so much conflicting information out there I decided to come here and ask some experts. Salt storage, I know how to use salts and how to generate hashes, but what I want to know is what the best method is for comparing the user hash stored in the database being sent from the client. If I have an MVC page that users a login, that login has to post (in SSL of course) the password to the server (which is the same location just with the POST command). What is the best way to post the password securely and then hash it? Google is a great tool but sometimes has too much conflicting info to know what to believe. Some say they keep the salt a secret while others say don't worry about it. I like PBKDF2 with SHA-512 to generate a hash :)

 

EDIT: Also, do you store the salt in a separate field in the user table or do you compute it in some other way?

Link to comment
https://www.neowin.net/forum/topic/1163508-web-server-salt-storage/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

If you have an SSL then you can use public key to encrypt the password before sending it to the server and then decrypt it on the other end.

 

Keeping in mind though any encryption you do have to be done at a client level and not in code behind as doing so will be done at a server level anyways and thus defeating the purpose of it. Someone correct me if I am wrong.

 

If you use HTTPS then technically you are safe. Nothing is safe but technically...

 

EDIT : I generate 2 salts for a given user and have another field that dictates how they are used.

 

Table Structure:

UserName

Salt1

Salt2

SaltNature

Hash

 

Salt Nature is an ENUM with 3 Values:

Before = Password + Salt1 + Salt2 (I don't actually save the password but I use this formula to calculate the Hash)

Middle = Salt1 + Password + Salt2 (I don't actually save the password but I use this formula to calculate the Hash)

After = Salt1 + Salt2 + Password (I don't actually save the password but I use this formula to calculate the Hash)

 

Hope this helps.

  • 0

Actually it does. Thanks for the advice :) But my general concern was I've noticed some posts from people working at microsoft that they retrieve the hash and salt from their repositories and then create user objects with hash and salt stored in them. Just seems like that would be an easy way for an attacker to grab what they need to start doing look up tables/etc.

  • 0

Yeah, but that's to do with objects in .net.

 

It's not as bad as it sounds. You just load the info into the object, then call the salting function and use the return to compare to the provided data from the client.

 

Unless the user finds a way to dump that object out of memory into a page, you'll be fine (and I don't even know if that's possible).

  • 0

wrack's instructions look correct, but you might also want to take a look at this article on secure salted password hashing. It very thoroughly explains how to do it the right way, and includes examples in numerous languages, including C#.

  • 0

There is just so much conflicting information out there I decided to come here and ask some experts. Salt storage, I know how to use salts and how to generate hashes, but what I want to know is what the best method is for comparing the user hash stored in the database being sent from the client. If I have an MVC page that users a login, that login has to post (in SSL of course) the password to the server (which is the same location just with the POST command). What is the best way to post the password securely and then hash it? Google is a great tool but sometimes has too much conflicting info to know what to believe. Some say they keep the salt a secret while others say don't worry about it. I like PBKDF2 with SHA-512 to generate a hash :)

 

EDIT: Also, do you store the salt in a separate field in the user table or do you compute it in some other way?

I'm finding it a little difficult to determine exactly what you want answers to...
  • Verifying a login: Search the database for a user record with a matching username (I would avoid any 'LIMIT 1' clause on the SQL query to avoid any possibility of timing attacks from giving away whether a username on its own is valid or not), and return the salt and hash. If a user was found, re-compute the hash using the salt and the POSTed password. Compare this hash with the hash retrieved from the database.
  • Secure transfer of password from client to server: SSL (HTTPS)!
  • Keeping salts secret... I think you were getting confused over something irrelevant, as mentioned below.
  • Storing salts: Store them in a separate field or concatenated to the hash, your choice!

If you have an SSL then you can use public key to encrypt the password before sending it to the server and then decrypt it on the other end.

 

Keeping in mind though any encryption you do have to be done at a client level and not in code behind as doing so will be done at a server level anyways and thus defeating the purpose of it. Someone correct me if I am wrong.

What on earth are you talking about.

 

EDIT : I generate 2 salts for a given user and have another field that dictates how they are used.

 

Table Structure:

UserName

Salt1

Salt2

SaltNature

Hash

 

Salt Nature is an ENUM with 3 Values:

Before = Password + Salt1 + Salt2 (I don't actually save the password but I use this formula to calculate the Hash)

Middle = Salt1 + Password + Salt2 (I don't actually save the password but I use this formula to calculate the Hash)

After = Salt1 + Salt2 + Password (I don't actually save the password but I use this formula to calculate the Hash)

 

Hope this helps.

What the hell are you doing? This is just an overly complicated useless mess that's doing nothing to enhance security whatsoever. Keep things simple, use one salt and one means of concatenation in hashing only!

 

Actually it does. Thanks for the advice :) But my general concern was I've noticed some posts from people working at microsoft that they retrieve the hash and salt from their repositories and then create user objects with hash and salt stored in them. Just seems like that would be an easy way for an attacker to grab what they need to start doing look up tables/etc.

I think, as someone suggested above, you're a little confused about what's going on there and worrying about nothing.

 

wrack's instructions look correct, but you might also want to take a look at this article on secure salted password hashing. It very thoroughly explains how to do it the right way, and includes examples in numerous languages, including C#.

Good article!
This topic is now closed to further replies.
  • Posts

    • SQL Server Management Studio 22.7 brings "What's New" page, T-SQL formatting, and lots more by Usama Jawad SQL Server Management Studio (SSMS) is the tool of choice for most developers working with SQL infrastructure and data. Microsoft recently released SSMS version 22, and in the past few months, it has been steadily releasing point upgrades to refine the integrated development environment (IDE). Now, it has released SSMS version 22.7.0 with a bunch of new features and interfaces. For starters, SSMS 22.7 has netted a native "What's New" page, which highlights the top features and bug fixes present in the latest release. However, Microsoft says that this page won't annoy you much as it will only show up each time you update SSMS, and once you dismiss it, it won't be shown again to you until the next release. Secondly, Microsoft has finally introduced T-SQL formatting inside SSMS. The good thing about this is that it does not require installing any additional components, as it is built into the native experience. All you have to do is right-click the query editor window and select Format SQL from the context menu. Additionally, you also have several customization options at your disposal, such as the ability to automatically place semicolons at the end of a statement, split clauses across multiple lines, and more. However, this capability is only in preview for now. Additionally, Microsoft has introduced a preview of Agent Mode, which allows the AI model to automatically perform complex workflows on your behalf. Furthermore, Agent Mode will operate in read-only mode by default, so that you don't have to worry about the AI model accidentally deleting your data. On a related note, Microsoft is finally allowing users to configure the execution context of GitHub Copilot. This can be controlled per database using the CONSTITUTION.md file, where you specify the user details for the agentic executor. You can find details about this and additional bugfixes in Microsoft's blog post here.
    • I only use 3 extensions in Zen. I don't need or want a ton of stuff in my browser i don't use.
    • I prefer to choose my own ad bockers, not what the browser seems to think I need. i remember the days when a browser was just that, now they try and be everything and add stuff in that not all of us want. I bet Brave is full of AI rubbish? I will stick with Zen, not perfect, but better than others.
    • PDF-XChange Editor 11.0.1.0 by Razvan Serea PDF-XChange Editor is a comprehensive PDF editor that allows you to create, view, edit, annotate, and digitally sign PDF documents with ease. With advanced features like OCR, document security, and PDF optimization, PDF-XChange Editor is a powerful tool for both personal and professional use. Whether you need to edit text, images, or links, or add comments, stamps, or watermarks, PDF-XChange Editor provides all the necessary tools to make your PDFs look perfect. Additionally, it supports a wide range of file formats, including PDF, XPS, and DOCX, making it easy to convert and share your documents. PDF-XChange Editor key features: Edit text and images in PDF documents Add and remove pages from PDF files Annotate and markup PDFs with comments, highlights, and stamps Use OCR to convert scanned documents into searchable text Create and fill out PDF forms Sign and certify PDF documents digitally Add and edit hyperlinks within PDFs Extract text and images from PDF files Batch process multiple PDF files at once Customize the interface to your preferences Work with multiple documents in tabs Convert PDFs to other formats such as Word, Excel, and HTML Use advanced redaction tools to permanently remove sensitive information Add customizable headers and footers to PDFs Merge multiple PDF documents into a single file Split PDF documents into multiple files Add watermarks to PDF documents Use the measurement tools to calculate distances and areas in PDFs ....and much more PDF-XChange Editor 11.0.1.0 changelog: Fixed a crash in the new Open/Save dialog box when creating a new folder in an unavailable network path. (49552) Fixed a rare/infrequent crash on some dynamic XFA forms after changing their field values. [installer] Fixed an issue where shortcuts were lost during an upgrade from the previous version. [installer] Fixed an issue preventing migration of serial keys during updates from version 10. Fixed the issues with the shell context menu after installation of version 11. Fixed the issue with filtering comments. (49478) Fixed the issue that caused "Error [IO subsystem]: Invalid access mode." when converting PDFs to MS Office formats. Fixed an issue with the context menu position on some multi-monitor systems. (48467) Fixed an issue with handling complex custom file filters, displayed by JS, in the new Open/Save Files dialog box. (49486) Fixed several issues with the new 'Select Folder' dialog box. (49505) Fixed an issue with the new custom 'Open File' dialog box when using double-click to open it. (49498) Fixed an 'infinite' loop/proliferation in the 'Open Files' and 'Manage Places' dialog boxes. (49526) Fixed an issue with handling the mouse wheel inside the document "Find" box. (49539) Fixed an incorrect behaviour in the 'Go back (Alt+Left)' button in the new Open/Save Files dialog box. (49510) Fixed an issue with the shortcut keys (Alt+Left/Right) after navigating via breadcrumb paths in the new Open/Save Files dialog box. (49554) [installer] Fixed an issue with redrawing the progress text in the EXE installers. Fixed the issue where a mouse click outside of the polyline/polygon context menu during annotation creation would cancel the annotation. (49475) We switched back to using the system Open/Save/SelectFolder dialog box by default, instead of using the new one, because some popular features such as the QuickAccess/Recent items are missing in the new version. These will be added in a future release. Replaced the 'Extension' column in the new Open/Save File dialog box with a more user-friendly 'Type' column. Also fixed some issues when handling the 'Show file extension' option. (49497) Added the ability to authenticate local network shares in the new Open/Save Files dialog box. (49557) Improved the handling of dates after 01.01.2030 in XFA files - now such dates are stored properly when set via the dropdown widget. Flags NoZoom and NoRotate are now respected for only a limited subset of annotations. Download: PDF-XChange Editor (64-bit) | Portable ~300.0 MB (Shareware) Download: PDF-XChange Editor (32-bit) | Portable ~200.0 MB Download: PDF-XChange ARM64 | 276.0 MB Download: PDF-XChange Portable @PortableApps.com | 97.0 MB View: PDF-XChange Editor Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      johnjacobb40 earned a badge
      One Month Later
    • One Year In
      Primer1st earned a badge
      One Year In
    • Experienced
      JayZJay went up a rank
      Experienced
    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      513
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      144
    4. 4
      ATLien_0
      86
    5. 5
      Steven P.
      82
  • Tell a friend

    Love Neowin? Tell a friend!