TOM LEONARD: Donald Trump's enemies wishfully think he's a Big Mac away from a heart attack. How IS a burger addict whose only exercise is riding in a golf buggy and who only sleeps five hours a night so fighting fit at 78?
Elon Musk drops shocking detail into his influence over Trump as First Buddy lobbies for 'Bitcoin Jesus' to be pardoned
M25 recap after incident causes 5 miles of queues towards Dartford Crossing
Colchester boy who lost leg and survived cancer is recognised for his bravery
Carrie Underwood's list of demands for Trump's inauguration performance revealed after she threw a 'hissy fit'
The 'innocent' pre-show ritual that sparked Sutton Foster's romance with Hugh Jackman
Apple Intelligence turned on by default in upcoming macOS Sequoia 15.3, iOS 18.3
Ready or not, generative AI assistants and productivity aids are getting harder to avoid with a growing number of software vendors enabling them by default.…
CodeSOD: The 5-Digit Session Identifier
Sawyer was talking with a co-worker about how their unique session IDs got created. The concern was that they were only five characters long, which meant there could easily be collisions.
They started by looking at the random number generation function.
Public Function RandomNumberGenerator(ByVal min As Integer, ByVal max As Integer, Optional ByVal numDecimals As Integer = 0) As String '*** the generates a number as a string Dim strNum As New StringBuilder Dim rnd As New System.Random Dim i, x, n As Integer Try i = rnd.Next(min, max) If numDecimals > 0 Then Try strNum.Append("9", numDecimals) n = CType(strNum.ToString, Int32) x = rnd.Next(0, n) Catch ex As Exception x = 1 End Try End If strNum.Remove(0, strNum.Length) strNum.Append(i.ToString()) If numDecimals > 0 Then strNum.Append(".") If numDecimals > 99 Then numDecimals = 99 End If strNum.Append(x.ToString("D" & numDecimals.ToString())) End If Return strNum.ToString Catch Return "1.00" End Try End FunctionYou always know it's going to be bad when you see the random number generator returns a string.
If numDecimals is zero, the code is bad, but vaguely sane. Generate a random number using the built in functions, then return it- as a string.
It's the use of numDecimals which makes this weird. We start by appending "9"s to our string builder, converting it to an integer, and then generating a random number from zero to whatever number of nines we're using. This is the code of someone who hates and fears logarithms.
Then we clear out our string builder because we're starting over with the actual number. Then we append a ".", then we append our number, formatted with our number of decimals string, which we force to be no larger than 99. And this is where we get the special kind of weird.
When we're generating our random decimal number, we do this: strNum.Append("9", numDecimals). This is going to put numDecimals 9s on the string. E.g., if numDecimals is 9, this would set strNum to be 999999999. Thus, when we generate a random number, we generate one between 0 and 99999999.
But, when we append that formatted value to the string, we do this:
If numDecimals > 99 Then numDecimals = 99 End If strNum.Append(x.ToString("D" & numDecimals.ToString()))Here, we're treating numDecimals as a format string. We're only ever going to output two digits.
The only good news is that while this random function was used everywhere, it wasn't used to generate their random IDs. The bad news, this is how their random IDs.
Public Function RandomQueryStringGenerator() As String '*** the generates an alpha-numeric string 5 digits long such as aa7bb Dim strPwd As New StringBuilder Dim rnd As New System.Random Dim i As Integer Try For x As Integer = 1 To 5 Select Case x Case 1, 2, 4, 5, 8, 9 i = rnd.Next(97, 122) If i Mod 2 = 0 Then strPwd.Append(Chr(i).ToString().ToUpper()) Else strPwd.Append(Chr(i).ToString()) End If Case Else i = rnd.Next(0, 9) strPwd.Append(i.ToString()) End Select Next x Return strPwd.ToString() Catch Return String.Empty End Try End FunctionEmbattled Rachel Reeves jets off to World Economic Forum in Davos - despite fresh alarm over faltering UK economy and warnings from investors of 'debt death spiral'
Now Labour's Attorney General Lord Hermer dodges scrutiny - again
'Fairy porn' fans of romantasy novel about dragon riders swarm midnight release of new tome in scenes reminiscent of Harry Potter-mania
This church puts the heating on an hour a month for its six worshippers - but since it got a smart meter its bills have gone from £15 to £1,172
Idaho considers archaic execution practice as 'primary method' of killing prisoners after lethal injection fails
Benjamin Netanyahu piles pressure on Keir Starmer to restore all arms licences for Israel
Microsoft Loses Status as OpenAI's Exclusive Cloud Provider
Read more of this story at Slashdot.
Every change Donald Trump has made to the Oval Office as awkward detail risks sparking Cabinet feud
Barron Trump is touted for NBA career as the New York Knicks are urged to sign Donald's 6'7 son
Guess Who? Hollywood star shares sweet never before seen childhood photos as she releases new book
Southport 'cover-up' row grows: Police blame CPS for gagging them from revealing knifeman's terror links as Tories accuse PM of double standards over previous attack tweets
Silk Road Creator Ross Ulbricht Pardoned
Read more of this story at Slashdot.