Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

      June 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: My Identification

    CodeSOD: My Identification

    January 8, 2025

    Bejamin‘s team needed to generate a unique session ID value that can’t easily be guessed. The traditional way of doing this would be to generate cryptographically secure random bytes. Most languages, including PHP, have a solution for doing that.

    But you could also do this:

    protected function _createId()
    {
            $id = 0;
            while (strlen($id) < 32)
            {
                    $id .= mt_rand(0, mt_getrandmax());
            }
    
            $id = md5(uniqid($id, true));
            return $id;
    }
    

    Now, mt_rand is not cryptographically secure. They generate a random number (of arbitrary size) and concatenate it to a string. When the string is 32 characters long (including a leading zero), we call that enough.

    This is not generating random bytes. To the contrary, the bytes it’s generating are very not random, seeing as they’re constrained to a character between 0 and 9.

    We then pass that through the uniqid function. Now, uniqid also generates a non-cryptographically secure unique identifier. Here, we’re specifying our large number is the prefix to that unique ID, and asking for more randomness to be added (the true parameter). This is better than what they did with the while loop above, though still not the “correct” way to do it.

    Hostinger

    Finally, we pass it through the md5 algorithm to reduce it to a hash, because we just love hash collisions.

    It’s impressive that, given a chance to make a choice about security-related features, they were able to make every single wrong choice.

    This is also why you don’t implement this stuff yourself. There are far more ways to get it wrong than there are ways to get it right.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMarvel Rivals Season 1 is bringing the Fantastic Four — here’s the Invisible Woman in action
    Next Article Zasper – IDE for Data Science

    Related Posts

    News & Updates

    7 MagSafe accessories that I recommend every iPhone user should have

    June 1, 2025
    News & Updates

    I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2014-4114: Details on August BlackEnergy PowerPoint Campaigns

    Development

    What’s the point of Headless?

    Development

    As Xbox’s Ori franchise turns 10, developer Moon Studios is now self-publishing its action-RPG, No Rest for the Wicked

    News & Updates

    Eliminating Data Duplication: A Guide to Duplicate Rules in Salesforce

    Development
    Hostinger

    Highlights

    Development

    T-Mobile Also Hit in China-linked Telecom Network Breaches

    November 18, 2024

    T-Mobile has confirmed that it was hit during a recent wave of telecom network breaches…

    CVE-2025-45513 – Tenda FH451 Stack Overflow Vulnerability

    May 9, 2025

    This stuff is way better than super glue

    May 6, 2025

    7 of the best co-op games to play with your Player 2 on Valentine’s Day

    February 14, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.