Is it bad practice to prefix my hash with the algorithm used?











up vote
41
down vote

favorite
1












Let's say I have a database with a bunch of users in it. This user database would typically have a hashed password per user. Would it be bad practice to prefix this hash with the hashing algorithm used?



For instance, instead of the hash aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, I store sha1_aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, since the method for making the hash is SHA1.



I noticed Argon2 does this, and I actually think it is quite convenient, because it makes it easier to partially migrate to newer hashing algorithms for newer users over time.










share|improve this question









New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 20




    From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
    – Heinzi
    2 days ago






  • 34




    @Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
    – kasperd
    2 days ago






  • 3




    @Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
    – Barmar
    2 days ago






  • 22




    @Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
    – Davor
    2 days ago






  • 8




    My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
    – Polynomial
    yesterday















up vote
41
down vote

favorite
1












Let's say I have a database with a bunch of users in it. This user database would typically have a hashed password per user. Would it be bad practice to prefix this hash with the hashing algorithm used?



For instance, instead of the hash aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, I store sha1_aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, since the method for making the hash is SHA1.



I noticed Argon2 does this, and I actually think it is quite convenient, because it makes it easier to partially migrate to newer hashing algorithms for newer users over time.










share|improve this question









New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 20




    From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
    – Heinzi
    2 days ago






  • 34




    @Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
    – kasperd
    2 days ago






  • 3




    @Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
    – Barmar
    2 days ago






  • 22




    @Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
    – Davor
    2 days ago






  • 8




    My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
    – Polynomial
    yesterday













up vote
41
down vote

favorite
1









up vote
41
down vote

favorite
1






1





Let's say I have a database with a bunch of users in it. This user database would typically have a hashed password per user. Would it be bad practice to prefix this hash with the hashing algorithm used?



For instance, instead of the hash aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, I store sha1_aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, since the method for making the hash is SHA1.



I noticed Argon2 does this, and I actually think it is quite convenient, because it makes it easier to partially migrate to newer hashing algorithms for newer users over time.










share|improve this question









New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Let's say I have a database with a bunch of users in it. This user database would typically have a hashed password per user. Would it be bad practice to prefix this hash with the hashing algorithm used?



For instance, instead of the hash aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, I store sha1_aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d, since the method for making the hash is SHA1.



I noticed Argon2 does this, and I actually think it is quite convenient, because it makes it easier to partially migrate to newer hashing algorithms for newer users over time.







passwords hash






share|improve this question









New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









schroeder

69.1k25146184




69.1k25146184






New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Mathias Lykkegaard Lorenzen

30625




30625




New contributor




Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mathias Lykkegaard Lorenzen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 20




    From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
    – Heinzi
    2 days ago






  • 34




    @Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
    – kasperd
    2 days ago






  • 3




    @Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
    – Barmar
    2 days ago






  • 22




    @Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
    – Davor
    2 days ago






  • 8




    My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
    – Polynomial
    yesterday














  • 20




    From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
    – Heinzi
    2 days ago






  • 34




    @Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
    – kasperd
    2 days ago






  • 3




    @Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
    – Barmar
    2 days ago






  • 22




    @Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
    – Davor
    2 days ago






  • 8




    My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
    – Polynomial
    yesterday








20




20




From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
– Heinzi
2 days ago




From a security point-of-view, it's fine. From a database point-of-view, 1NF recommends that you use two separate fields instead of string concatenation.
– Heinzi
2 days ago




34




34




@Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
– kasperd
2 days ago




@Heinzi Whether that's a sensible recommendation or not depends on how the hash is used. For example there are password hashing libraries which use strings with a concatenation of algorithm, salt, hash, and possibly other fields. When using such a library the string should be treated as an opaque value by the application. The application doesn't need to know the structure of the string, the library takes care of that. And the number of fields can depend on the algorithm in use. When using such a library it is good practice to store the concatenated string in the database.
– kasperd
2 days ago




3




3




@Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
– Barmar
2 days ago




@Heinzi OTOH, software modularity can argue against storing them as separate fields. You can write a generic "verify password" that extracts the algorithm from the hash if appropriate, without it having to be an explicit parameter.
– Barmar
2 days ago




22




22




@Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
– Davor
2 days ago




@Heinzi - that's not true any more than storing a date as separate columns for day, month and year. What is an atomic attribute is domain specific. And in every domain I've ever seen, hash and the algorithm specification that produced it are useless without each other, and are thus atomic.
– Davor
2 days ago




8




8




My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
– Polynomial
yesterday




My biggest concern here is that you're using SHA. Instead consider Argon2, scrypt, bcrypt, or PBKDF2 (also known as RFC 2898 Derivation).
– Polynomial
yesterday










5 Answers
5






active

oldest

votes

















up vote
90
down vote













Many different password hashing systems do this. The type of hashing mechanism used should not be (and should not need to be) a secret. Kerckhoffs's principle says:




A cryptosystem should be secure even if everything about the system,
except the key, is public knowledge.




So, if your system is properly secure, it should not matter if the hash mechanism is exposed.






share|improve this answer

















  • 8




    Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
    – leftaroundabout
    2 days ago






  • 6




    @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
    – schroeder
    2 days ago








  • 2




    Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
    – leftaroundabout
    2 days ago








  • 17




    I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
    – Nathan Merrill
    2 days ago






  • 9




    @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
    – Jeremy
    2 days ago


















up vote
33
down vote













I agree with schroeder that this is OK to do. Even without a prefix, an attacker can probably figure out what algorithm you are using. And anyway, it is the strength of the hashing algorithm that protects the passwords, not the secrecy of the algorithm.



Note that many hashing algorithms and libraries already do this for you. They embed all the relevant information - algorithm, cost factors, salt, the actual hash - into one serialized string. See for instance the Modular Crypt Format or the PHP password_hash function. So don't go making up your own scheme. If you are using a descent hashing library you already got one.



Don't use SHA1 to hash passwords, though. That is not OK.






share|improve this answer





















  • Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
    – Mathias Lykkegaard Lorenzen
    2 days ago








  • 16




    @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
    – Anders
    2 days ago






  • 3




    @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
    – forest
    yesterday






  • 8




    It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
    – hlt
    yesterday






  • 1




    Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
    – FrederikNS
    yesterday


















up vote
12
down vote













No, it's not bad practice, and arguably, you should keep this information.



As you observe, this allows you to change algorithm for new passwords whenever you like, without invalidating all users' existing passwords (doing that tends to make you unpopular, for some reason).



There's an argument that this allows an attacker to search out the older, weaker passwords to attack first, but you haven't reduced their security at all (assuming Kerckhoff's Principle, that the algorithm itself mustn't need to be a secret).






share|improve this answer

















  • 1




    If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
    – supercat
    2 days ago


















up vote
8
down vote













It's good practice to store the hashing algorithm, but proper password hashing functions such as Argon2 and PBKDF2 already take care of this. It is however bad practice to use SHA1 or SHA256 alone for password hashing because they're a fixed (and relatively small) amount of work to crack using dictionary attacks and brute force. Those passwords should be migrated to a secure hashing function by rehashing the password on their next login. See https://crypto.stackexchange.com/a/45405 for details.






share|improve this answer








New contributor




leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    1
    down vote













    It's not bad practice, it's actually a common thing to do. In fact if you open the /etc/shadow file on a linux machine you will see your hashed password prefixed with $x$salt$ where x is a number indicating which hashing algorithm was used.



    Now a few things you might want to consider:




    • do not use SHA1 directly as a hashing algorithm. Use bcrypt or scrypt instead. These do use simple hashing algorithm like SHA1 as a base, but they run that several times over your secret in a way that makes it resistant to attacks and future-proof.

    • for practical reasons, since you're using a database and not a file, you might want to store the hashing method and salt in separate rows. However you can also choose to store the string starting with $x$salt$ in your database, and parse the salt and hashing method from that string at the time you check the password. It's probably fast enough that it makes no significant difference. And in both cases the security of your system will be the same.






    share|improve this answer








    New contributor




    Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


















    • The OP says in comments that SHA-1 was only used as an example and is not used in production
      – schroeder
      yesterday










    • One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
      – zaph
      yesterday











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "162"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Mathias Lykkegaard Lorenzen is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f197236%2fis-it-bad-practice-to-prefix-my-hash-with-the-algorithm-used%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    90
    down vote













    Many different password hashing systems do this. The type of hashing mechanism used should not be (and should not need to be) a secret. Kerckhoffs's principle says:




    A cryptosystem should be secure even if everything about the system,
    except the key, is public knowledge.




    So, if your system is properly secure, it should not matter if the hash mechanism is exposed.






    share|improve this answer

















    • 8




      Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
      – leftaroundabout
      2 days ago






    • 6




      @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
      – schroeder
      2 days ago








    • 2




      Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
      – leftaroundabout
      2 days ago








    • 17




      I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
      – Nathan Merrill
      2 days ago






    • 9




      @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
      – Jeremy
      2 days ago















    up vote
    90
    down vote













    Many different password hashing systems do this. The type of hashing mechanism used should not be (and should not need to be) a secret. Kerckhoffs's principle says:




    A cryptosystem should be secure even if everything about the system,
    except the key, is public knowledge.




    So, if your system is properly secure, it should not matter if the hash mechanism is exposed.






    share|improve this answer

















    • 8




      Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
      – leftaroundabout
      2 days ago






    • 6




      @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
      – schroeder
      2 days ago








    • 2




      Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
      – leftaroundabout
      2 days ago








    • 17




      I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
      – Nathan Merrill
      2 days ago






    • 9




      @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
      – Jeremy
      2 days ago













    up vote
    90
    down vote










    up vote
    90
    down vote









    Many different password hashing systems do this. The type of hashing mechanism used should not be (and should not need to be) a secret. Kerckhoffs's principle says:




    A cryptosystem should be secure even if everything about the system,
    except the key, is public knowledge.




    So, if your system is properly secure, it should not matter if the hash mechanism is exposed.






    share|improve this answer












    Many different password hashing systems do this. The type of hashing mechanism used should not be (and should not need to be) a secret. Kerckhoffs's principle says:




    A cryptosystem should be secure even if everything about the system,
    except the key, is public knowledge.




    So, if your system is properly secure, it should not matter if the hash mechanism is exposed.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 days ago









    schroeder

    69.1k25146184




    69.1k25146184








    • 8




      Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
      – leftaroundabout
      2 days ago






    • 6




      @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
      – schroeder
      2 days ago








    • 2




      Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
      – leftaroundabout
      2 days ago








    • 17




      I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
      – Nathan Merrill
      2 days ago






    • 9




      @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
      – Jeremy
      2 days ago














    • 8




      Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
      – leftaroundabout
      2 days ago






    • 6




      @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
      – schroeder
      2 days ago








    • 2




      Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
      – leftaroundabout
      2 days ago








    • 17




      I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
      – Nathan Merrill
      2 days ago






    • 9




      @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
      – Jeremy
      2 days ago








    8




    8




    Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
    – leftaroundabout
    2 days ago




    Why “should not be”? Should not need to be secret is Kerckhoffs's principle, but as long as it doesn't cause you to compromise on the key safety it certainly can't cause harm either if the hash algorithm is secret too.
    – leftaroundabout
    2 days ago




    6




    6




    @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
    – schroeder
    2 days ago






    @leftaroundabout that's about Kerckhoffs's. Operationally and policy-wise, to classify the hashing algorithm as a secret is a problem. It attempts to provide security by obscurity, and it introduces control costs that outweigh the benefits. Not to mention the practical use case provided by Toby Speight. It's not about prepending the alo type, it's about the classification of the data about the algo type.
    – schroeder
    2 days ago






    2




    2




    Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
    – leftaroundabout
    2 days ago






    Classifying it as a secret is not necessary for it being secret. It may be secret incidentally, for performance reasons.
    – leftaroundabout
    2 days ago






    17




    17




    I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
    – Nathan Merrill
    2 days ago




    I was under the impression that adding "security by obscurity" is still a good thing. Systems should be secure, even if you know all of the details of the system, but adding obscurity adds security (to slow down attackers, to hide systems when 0-day bugs get found, etc). It this fair?
    – Nathan Merrill
    2 days ago




    9




    9




    @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
    – Jeremy
    2 days ago




    @NathanMerrill I would say that it should be taken on a case-by-case basis. In this case, I think the benefit of having the algorithm stored with the hash significantly outweighs the very slight security benefit you'd get by obscuring it.
    – Jeremy
    2 days ago












    up vote
    33
    down vote













    I agree with schroeder that this is OK to do. Even without a prefix, an attacker can probably figure out what algorithm you are using. And anyway, it is the strength of the hashing algorithm that protects the passwords, not the secrecy of the algorithm.



    Note that many hashing algorithms and libraries already do this for you. They embed all the relevant information - algorithm, cost factors, salt, the actual hash - into one serialized string. See for instance the Modular Crypt Format or the PHP password_hash function. So don't go making up your own scheme. If you are using a descent hashing library you already got one.



    Don't use SHA1 to hash passwords, though. That is not OK.






    share|improve this answer





















    • Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
      – Mathias Lykkegaard Lorenzen
      2 days ago








    • 16




      @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
      – Anders
      2 days ago






    • 3




      @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
      – forest
      yesterday






    • 8




      It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
      – hlt
      yesterday






    • 1




      Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
      – FrederikNS
      yesterday















    up vote
    33
    down vote













    I agree with schroeder that this is OK to do. Even without a prefix, an attacker can probably figure out what algorithm you are using. And anyway, it is the strength of the hashing algorithm that protects the passwords, not the secrecy of the algorithm.



    Note that many hashing algorithms and libraries already do this for you. They embed all the relevant information - algorithm, cost factors, salt, the actual hash - into one serialized string. See for instance the Modular Crypt Format or the PHP password_hash function. So don't go making up your own scheme. If you are using a descent hashing library you already got one.



    Don't use SHA1 to hash passwords, though. That is not OK.






    share|improve this answer





















    • Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
      – Mathias Lykkegaard Lorenzen
      2 days ago








    • 16




      @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
      – Anders
      2 days ago






    • 3




      @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
      – forest
      yesterday






    • 8




      It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
      – hlt
      yesterday






    • 1




      Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
      – FrederikNS
      yesterday













    up vote
    33
    down vote










    up vote
    33
    down vote









    I agree with schroeder that this is OK to do. Even without a prefix, an attacker can probably figure out what algorithm you are using. And anyway, it is the strength of the hashing algorithm that protects the passwords, not the secrecy of the algorithm.



    Note that many hashing algorithms and libraries already do this for you. They embed all the relevant information - algorithm, cost factors, salt, the actual hash - into one serialized string. See for instance the Modular Crypt Format or the PHP password_hash function. So don't go making up your own scheme. If you are using a descent hashing library you already got one.



    Don't use SHA1 to hash passwords, though. That is not OK.






    share|improve this answer












    I agree with schroeder that this is OK to do. Even without a prefix, an attacker can probably figure out what algorithm you are using. And anyway, it is the strength of the hashing algorithm that protects the passwords, not the secrecy of the algorithm.



    Note that many hashing algorithms and libraries already do this for you. They embed all the relevant information - algorithm, cost factors, salt, the actual hash - into one serialized string. See for instance the Modular Crypt Format or the PHP password_hash function. So don't go making up your own scheme. If you are using a descent hashing library you already got one.



    Don't use SHA1 to hash passwords, though. That is not OK.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 days ago









    Anders

    47k21132155




    47k21132155












    • Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
      – Mathias Lykkegaard Lorenzen
      2 days ago








    • 16




      @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
      – Anders
      2 days ago






    • 3




      @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
      – forest
      yesterday






    • 8




      It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
      – hlt
      yesterday






    • 1




      Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
      – FrederikNS
      yesterday


















    • Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
      – Mathias Lykkegaard Lorenzen
      2 days ago








    • 16




      @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
      – Anders
      2 days ago






    • 3




      @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
      – forest
      yesterday






    • 8




      It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
      – hlt
      yesterday






    • 1




      Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
      – FrederikNS
      yesterday
















    Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
    – Mathias Lykkegaard Lorenzen
    2 days ago






    Yeah I used SHA1 because I the hash of "hello" was too long for an example in SHA512.
    – Mathias Lykkegaard Lorenzen
    2 days ago






    16




    16




    @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
    – Anders
    2 days ago




    @MathiasLykkegaardLorenzen Don't use SHA512 either, unless it is just a component in a bigger scheme with more iterations. But off course for an example, anything goes! :-)
    – Anders
    2 days ago




    3




    3




    @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
    – forest
    yesterday




    @MathiasLykkegaardLorenzen And don't just use multiple iterations either! Use a proven construct like PBKDF2, which uses HMAC (not just raw hash iterations).
    – forest
    yesterday




    8




    8




    It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
    – hlt
    yesterday




    It's not insecure for what it was designed for (i.e. hashing data), but it was designed to be fast. You want your password hash function to be slow to stave off brute force attempts.
    – hlt
    yesterday




    1




    1




    Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
    – FrederikNS
    yesterday




    Yes it still matters. Hashing functions are not meant for password storage due to their speed. With a single p3.16xlarge instance on Amazon, you can do 17.28 billion guesses per second on SHA512. That means that you can crack any 8 character password of letters and numbers in only 151.17 seconds. Key derivation functions are made for storing passwords as they are slow. With bcrypt on workfactor 12 you can only do 424200 guesses per second. That would take 34.8 days per password. Additionally bcrypt and argon2 has built in salts, so you don't have to worry about salting the passwords.
    – FrederikNS
    yesterday










    up vote
    12
    down vote













    No, it's not bad practice, and arguably, you should keep this information.



    As you observe, this allows you to change algorithm for new passwords whenever you like, without invalidating all users' existing passwords (doing that tends to make you unpopular, for some reason).



    There's an argument that this allows an attacker to search out the older, weaker passwords to attack first, but you haven't reduced their security at all (assuming Kerckhoff's Principle, that the algorithm itself mustn't need to be a secret).






    share|improve this answer

















    • 1




      If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
      – supercat
      2 days ago















    up vote
    12
    down vote













    No, it's not bad practice, and arguably, you should keep this information.



    As you observe, this allows you to change algorithm for new passwords whenever you like, without invalidating all users' existing passwords (doing that tends to make you unpopular, for some reason).



    There's an argument that this allows an attacker to search out the older, weaker passwords to attack first, but you haven't reduced their security at all (assuming Kerckhoff's Principle, that the algorithm itself mustn't need to be a secret).






    share|improve this answer

















    • 1




      If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
      – supercat
      2 days ago













    up vote
    12
    down vote










    up vote
    12
    down vote









    No, it's not bad practice, and arguably, you should keep this information.



    As you observe, this allows you to change algorithm for new passwords whenever you like, without invalidating all users' existing passwords (doing that tends to make you unpopular, for some reason).



    There's an argument that this allows an attacker to search out the older, weaker passwords to attack first, but you haven't reduced their security at all (assuming Kerckhoff's Principle, that the algorithm itself mustn't need to be a secret).






    share|improve this answer












    No, it's not bad practice, and arguably, you should keep this information.



    As you observe, this allows you to change algorithm for new passwords whenever you like, without invalidating all users' existing passwords (doing that tends to make you unpopular, for some reason).



    There's an argument that this allows an attacker to search out the older, weaker passwords to attack first, but you haven't reduced their security at all (assuming Kerckhoff's Principle, that the algorithm itself mustn't need to be a secret).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 days ago









    Toby Speight

    1,054415




    1,054415








    • 1




      If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
      – supercat
      2 days ago














    • 1




      If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
      – supercat
      2 days ago








    1




    1




    If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
    – supercat
    2 days ago




    If one can store a combination of algorithms and salts, there's no need to keep weaker passwords once stronger algorithms are available. If the current entry says that putting the password through weakAlgorithm with salt1 yields X, simply compute Y by putting X through a strongerAlgorithm with salt2 then change the entry to say that putting the password through the weakAlgorithm with salt1, and then putting the result of that through a stronger algorithm with salt2, will yield Y. No need to wait for the user to log in.
    – supercat
    2 days ago










    up vote
    8
    down vote













    It's good practice to store the hashing algorithm, but proper password hashing functions such as Argon2 and PBKDF2 already take care of this. It is however bad practice to use SHA1 or SHA256 alone for password hashing because they're a fixed (and relatively small) amount of work to crack using dictionary attacks and brute force. Those passwords should be migrated to a secure hashing function by rehashing the password on their next login. See https://crypto.stackexchange.com/a/45405 for details.






    share|improve this answer








    New contributor




    leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      8
      down vote













      It's good practice to store the hashing algorithm, but proper password hashing functions such as Argon2 and PBKDF2 already take care of this. It is however bad practice to use SHA1 or SHA256 alone for password hashing because they're a fixed (and relatively small) amount of work to crack using dictionary attacks and brute force. Those passwords should be migrated to a secure hashing function by rehashing the password on their next login. See https://crypto.stackexchange.com/a/45405 for details.






      share|improve this answer








      New contributor




      leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















        up vote
        8
        down vote










        up vote
        8
        down vote









        It's good practice to store the hashing algorithm, but proper password hashing functions such as Argon2 and PBKDF2 already take care of this. It is however bad practice to use SHA1 or SHA256 alone for password hashing because they're a fixed (and relatively small) amount of work to crack using dictionary attacks and brute force. Those passwords should be migrated to a secure hashing function by rehashing the password on their next login. See https://crypto.stackexchange.com/a/45405 for details.






        share|improve this answer








        New contributor




        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        It's good practice to store the hashing algorithm, but proper password hashing functions such as Argon2 and PBKDF2 already take care of this. It is however bad practice to use SHA1 or SHA256 alone for password hashing because they're a fixed (and relatively small) amount of work to crack using dictionary attacks and brute force. Those passwords should be migrated to a secure hashing function by rehashing the password on their next login. See https://crypto.stackexchange.com/a/45405 for details.







        share|improve this answer








        New contributor




        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 2 days ago









        leo v

        811




        811




        New contributor




        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        leo v is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















            up vote
            1
            down vote













            It's not bad practice, it's actually a common thing to do. In fact if you open the /etc/shadow file on a linux machine you will see your hashed password prefixed with $x$salt$ where x is a number indicating which hashing algorithm was used.



            Now a few things you might want to consider:




            • do not use SHA1 directly as a hashing algorithm. Use bcrypt or scrypt instead. These do use simple hashing algorithm like SHA1 as a base, but they run that several times over your secret in a way that makes it resistant to attacks and future-proof.

            • for practical reasons, since you're using a database and not a file, you might want to store the hashing method and salt in separate rows. However you can also choose to store the string starting with $x$salt$ in your database, and parse the salt and hashing method from that string at the time you check the password. It's probably fast enough that it makes no significant difference. And in both cases the security of your system will be the same.






            share|improve this answer








            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • The OP says in comments that SHA-1 was only used as an example and is not used in production
              – schroeder
              yesterday










            • One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
              – zaph
              yesterday















            up vote
            1
            down vote













            It's not bad practice, it's actually a common thing to do. In fact if you open the /etc/shadow file on a linux machine you will see your hashed password prefixed with $x$salt$ where x is a number indicating which hashing algorithm was used.



            Now a few things you might want to consider:




            • do not use SHA1 directly as a hashing algorithm. Use bcrypt or scrypt instead. These do use simple hashing algorithm like SHA1 as a base, but they run that several times over your secret in a way that makes it resistant to attacks and future-proof.

            • for practical reasons, since you're using a database and not a file, you might want to store the hashing method and salt in separate rows. However you can also choose to store the string starting with $x$salt$ in your database, and parse the salt and hashing method from that string at the time you check the password. It's probably fast enough that it makes no significant difference. And in both cases the security of your system will be the same.






            share|improve this answer








            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















            • The OP says in comments that SHA-1 was only used as an example and is not used in production
              – schroeder
              yesterday










            • One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
              – zaph
              yesterday













            up vote
            1
            down vote










            up vote
            1
            down vote









            It's not bad practice, it's actually a common thing to do. In fact if you open the /etc/shadow file on a linux machine you will see your hashed password prefixed with $x$salt$ where x is a number indicating which hashing algorithm was used.



            Now a few things you might want to consider:




            • do not use SHA1 directly as a hashing algorithm. Use bcrypt or scrypt instead. These do use simple hashing algorithm like SHA1 as a base, but they run that several times over your secret in a way that makes it resistant to attacks and future-proof.

            • for practical reasons, since you're using a database and not a file, you might want to store the hashing method and salt in separate rows. However you can also choose to store the string starting with $x$salt$ in your database, and parse the salt and hashing method from that string at the time you check the password. It's probably fast enough that it makes no significant difference. And in both cases the security of your system will be the same.






            share|improve this answer








            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            It's not bad practice, it's actually a common thing to do. In fact if you open the /etc/shadow file on a linux machine you will see your hashed password prefixed with $x$salt$ where x is a number indicating which hashing algorithm was used.



            Now a few things you might want to consider:




            • do not use SHA1 directly as a hashing algorithm. Use bcrypt or scrypt instead. These do use simple hashing algorithm like SHA1 as a base, but they run that several times over your secret in a way that makes it resistant to attacks and future-proof.

            • for practical reasons, since you're using a database and not a file, you might want to store the hashing method and salt in separate rows. However you can also choose to store the string starting with $x$salt$ in your database, and parse the salt and hashing method from that string at the time you check the password. It's probably fast enough that it makes no significant difference. And in both cases the security of your system will be the same.







            share|improve this answer








            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer






            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered yesterday









            Nicolas Marshall

            1113




            1113




            New contributor




            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            Nicolas Marshall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.












            • The OP says in comments that SHA-1 was only used as an example and is not used in production
              – schroeder
              yesterday










            • One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
              – zaph
              yesterday


















            • The OP says in comments that SHA-1 was only used as an example and is not used in production
              – schroeder
              yesterday










            • One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
              – zaph
              yesterday
















            The OP says in comments that SHA-1 was only used as an example and is not used in production
            – schroeder
            yesterday




            The OP says in comments that SHA-1 was only used as an example and is not used in production
            – schroeder
            yesterday












            One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
            – zaph
            yesterday




            One needs to use more than "run that several times", it needs to have a CPU utilization or ~100ms and a random salt.
            – zaph
            yesterday










            Mathias Lykkegaard Lorenzen is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Mathias Lykkegaard Lorenzen is a new contributor. Be nice, and check out our Code of Conduct.













            Mathias Lykkegaard Lorenzen is a new contributor. Be nice, and check out our Code of Conduct.












            Mathias Lykkegaard Lorenzen is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsecurity.stackexchange.com%2fquestions%2f197236%2fis-it-bad-practice-to-prefix-my-hash-with-the-algorithm-used%23new-answer', 'question_page');
            }
            );

            Post as a guest