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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

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

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 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

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

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

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 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

    How Red Hat just quietly, radically transformed enterprise server Linux

    June 2, 2025
    News & Updates

    OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CMU Researchers Propose XEUS: A Cross-lingual Encoder for Universal Speech trained in 4000+ Languages

    Development

    Extend large language models powered by Amazon SageMaker AI using Model Context Protocol

    Machine Learning

    CVE-2025-46827 – Graylog HTML Form Cookie Disclosure

    Common Vulnerabilities and Exposures (CVEs)

    React Native Bottom Sheet Stepper for Multi-Step Flows

    Development

    Highlights

    Collective #849

    June 21, 2024

    5 hard truths for young designers * Anchor position tool * “Dots” Custom Element Source:…

    How Skyflow creates technical content in days using Amazon Bedrock

    June 5, 2024

    This subscription-free smart ring with remarkable battery life isn’t from Oura or Samsung

    February 11, 2025

    Dragora – independent Linux distribution

    January 17, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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