<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/index.php?action=history&amp;feed=atom&amp;title=Time_and_Randomness_Management_Library</id>
		<title>Time and Randomness Management Library - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/index.php?action=history&amp;feed=atom&amp;title=Time_and_Randomness_Management_Library"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Time_and_Randomness_Management_Library&amp;action=history"/>
		<updated>2026-05-06T13:01:12Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Time_and_Randomness_Management_Library&amp;diff=156023&amp;oldid=prev</id>
		<title>Rahul Chaudhary at 13:49, 25 July 2013</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Time_and_Randomness_Management_Library&amp;diff=156023&amp;oldid=prev"/>
				<updated>2013-07-25T13:49:59Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 13:49, 25 July 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l6&quot; &gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;li&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;li&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;b&amp;gt;Random: &amp;lt;/b&amp;gt;This library is the central library to generate random numbers and strings for the whole application. Using this library we can generate cryptographically random strings of any length. This function also produces random integers.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;b&amp;gt;Random: &amp;lt;/b&amp;gt;This library is the central library to generate random numbers and strings for the whole application. Using this library we can generate cryptographically random strings of any length. This function also produces random integers.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;BR&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;h4&amp;gt;Need for Time and Randomness Library&amp;lt;/h4&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;p&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;b&amp;gt;Time: &amp;lt;/b&amp;gt;With time, developers often feel the need to change the system time - maybe for testing purpose or for different time-zones. Whatever is the case, developers find a hard time using normal PHP's &amp;quot;time()&amp;quot; function. To change time to some other time, they have to change system time, which is not only insecure, but will also affect many functions inside the host operating systems which heavily depend on time, such as Cron jobs and time-triggered events. This also is not recommended on main servers as this can corrupt other authentication servers such as &amp;quot;Kerberos&amp;quot;. Also it may give an attacker a window to launch some attacks to time-dependent functions. Thus, for all the reasons stated above, we strongly felt the need to generate a wrapper for time, so that change of time within an application can be isolated and controlled. With this we mean that change in time in one application must not affect any other application or system outside the scope of the application. To keep consistency between our application and PHP, we created our &amp;quot;time()&amp;quot; function with the same name as PHP's &amp;quot;time()&amp;quot; function. Thus within our library, calling &amp;quot;time()&amp;quot; function automatically calls PHPSEC's time() function rather than PHP's time() function.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;p&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;b&amp;gt;Random: &amp;lt;/b&amp;gt;Similarly the need of randomness is crucial in an application. With random strings being so important in a secure application and because not having a separate function in PHP's library for generating a cryptographically secure random string of desired length, we decided to create a separate central library that can provide random strings of desired length. With this library the developers can create secure strings of desired length and can also generate a random integer within a desired range. To keep consistency between our application and PHP, we created our &amp;quot;rand()&amp;quot; function with the same name as PHP's &amp;quot;rand()&amp;quot; function. Thus within our library, calling &amp;quot;rand()&amp;quot; function automatically calls PHPSEC's rand() function rather than PHP's rand() function.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;BR&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;h4&amp;gt;PHPSEC Time and Randomness Library Implementation&amp;lt;/h4&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Time and Randomness libraries are core libraries. Unlike other libraries, core libraries are used by mostly all of the other libraries for various functions. With time and randomness being core, we can use their time() and rand() function wherever they are needed in the application. These libraries do not depend on any other component of the application and are truly stand-alone libraries. Their implementation details are as follows:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;h4&lt;/del&gt;&amp;gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Need for &lt;/del&gt;Time &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;and Randomness Library&lt;/del&gt;&amp;lt;/&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;h4&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;b&lt;/ins&gt;&amp;gt;Time&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;: &lt;/ins&gt;&amp;lt;/&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;b&lt;/ins&gt;&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Time library contains one function inside &amp;quot;phpsec&amp;quot; namespace - &amp;quot;&lt;/ins&gt;time&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;()&amp;quot;. This library takes two arguments - &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;first argument is &amp;quot;mode&amp;quot; and &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;next argument is &amp;quot;desired &lt;/ins&gt;time&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot;&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;By default &amp;quot;mode&amp;quot; &lt;/ins&gt;is &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot;CURR&amp;quot; and &amp;quot;desired &lt;/ins&gt;time&amp;quot; &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is &amp;quot;0&amp;quot;. Types of mode that are possible in our &lt;/ins&gt;time() function &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;are:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;With &lt;/del&gt;time&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;, developers often feel &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;need to change &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;system &lt;/del&gt;time &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;- maybe for testing purpose or for different time-zones&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Whatever &lt;/del&gt;is &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;the case, developers find a hard &lt;/del&gt;time &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;using normal PHP's &lt;/del&gt;&amp;quot;time()&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot; &lt;/del&gt;function. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;To change &lt;/del&gt;time to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;some other time&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;they have to change system time&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;which is not only insecure&lt;/del&gt;, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;but &lt;/del&gt;will &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;also affect many functions inside &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;host operating systems which heavily depend on &lt;/del&gt;time&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;, such as Cron jobs and &lt;/del&gt;time&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;-triggered events&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;This also is not recommended on main servers as this can corrupt other authentication servers such as &amp;quot;Kerberos&amp;quot;&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Also it may give an attacker a window &lt;/del&gt;to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;launch some attacks &lt;/del&gt;to time&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;-dependent functions&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Thus, for all &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;reasons stated above, we strongly felt &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;need &lt;/del&gt;to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;generate a wrapper for &lt;/del&gt;the time&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;, so &lt;/del&gt;that &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;change of time within an application can be isolated and controlled&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;With &lt;/del&gt;this &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;we mean that change in time in one application must &lt;/del&gt;not &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;affect any other application or system outside &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;scope of &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;application&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;ul&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;CURR: &amp;lt;/b&amp;gt;Used to request current time as specified&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;i.e. if the developer has set &lt;/ins&gt;time to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;March 7&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Sun&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;1971&lt;/ins&gt;, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;then this mode &lt;/ins&gt;will &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;return &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;current &lt;/ins&gt;time &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;that has passed since that time was kept.&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;SET: &amp;lt;/b&amp;gt;Used to set time to a desired &lt;/ins&gt;time. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The second argument here takes the desired time in unix timestamp format&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;RESET: &amp;lt;/b&amp;gt;Used to reset time &lt;/ins&gt;to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the original system time.&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;MOV: &amp;lt;/b&amp;gt;Used &lt;/ins&gt;to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;move &lt;/ins&gt;time &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;backward&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;The second argument here takes &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;time difference that is to be moved. e.g. 3600 will move &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;clock backward 3600 seconds.&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;b&amp;gt;SYS: &amp;lt;/b&amp;gt;Used &lt;/ins&gt;to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;request system time. This mode will return &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;correct system &lt;/ins&gt;time &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;irrespective of the fact &lt;/ins&gt;that &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the clock is moved forward or backward&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Note the &lt;/ins&gt;this &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;does &lt;/ins&gt;not &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;changes &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;user-defined time. This just returns &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;correct system time&lt;/ins&gt;.&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/li&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;BR&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;BR&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Similarly the need of randomness &lt;/del&gt;is &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;crucial in an application. With &lt;/del&gt;random &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;strings being so important in &lt;/del&gt;a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;secure application &lt;/del&gt;and &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;because not having a separate &lt;/del&gt;function &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;in PHP's library for generating &lt;/del&gt;a &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;cryptographically secure &lt;/del&gt;random string of &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;desired &lt;/del&gt;length&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;, we decided &lt;/del&gt;to &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;create a separate central library that can provide random strings &lt;/del&gt;of desired &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;length&lt;/del&gt;. &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;With this library &lt;/del&gt;the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;developers can create secure strings of desired length &lt;/del&gt;and &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;can also &lt;/del&gt;generate &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;a &lt;/del&gt;random &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;integer within a desired range&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;b&amp;gt;Random: &amp;lt;/b&amp;gt;Random library contains two functions inside &amp;quot;phpsec&amp;quot; namespace - &amp;quot;rand()&amp;quot; and &amp;quot;randstr()&amp;quot;. The former method &lt;/ins&gt;is &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;used to get &lt;/ins&gt;random &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;integer between &lt;/ins&gt;a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;specified range &lt;/ins&gt;and &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the latter &lt;/ins&gt;function &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is used to get &lt;/ins&gt;a random string of &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;specified &lt;/ins&gt;length&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;. The &amp;quot;rand()&amp;quot; function takes two parameters - &amp;quot;min (Defaults to 0)&amp;quot; and &amp;quot;max (Defaults &lt;/ins&gt;to &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;null)&amp;quot;. The other function &amp;quot;randstr()&amp;quot; takes only one parameter - the length &lt;/ins&gt;of &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the string &lt;/ins&gt;desired &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(defaults to 32)&lt;/ins&gt;. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;To generate a random string, we use &lt;/ins&gt;the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;openssl function (openssl_random_pseudo_bytes). If that function is somehow not present, we use (posix_getpid()) &lt;/ins&gt;and &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(memory_get_usage()) to &lt;/ins&gt;generate &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;the &lt;/ins&gt;random &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;string&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt;h4&amp;gt;Other Helpful Links&amp;lt;/h4&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rahul Chaudhary</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Time_and_Randomness_Management_Library&amp;diff=156022&amp;oldid=prev</id>
		<title>Rahul Chaudhary: Created page with &quot;&lt;h4&gt;Introduction&lt;/h4&gt; &lt;ul&gt; &lt;li&gt; &lt;b&gt;Time: &lt;/b&gt;This library is a wrapper library for PHPs own &quot;time()&quot; function. With the use of this library, our aim was to isolate our system ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Time_and_Randomness_Management_Library&amp;diff=156022&amp;oldid=prev"/>
				<updated>2013-07-25T12:55:33Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h4&amp;gt;Introduction&amp;lt;/h4&amp;gt; &amp;lt;ul&amp;gt; &amp;lt;li&amp;gt; &amp;lt;b&amp;gt;Time: &amp;lt;/b&amp;gt;This library is a wrapper library for PHPs own &amp;quot;time()&amp;quot; function. With the use of this library, our aim was to isolate our system ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h4&amp;gt;Introduction&amp;lt;/h4&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Time: &amp;lt;/b&amp;gt;This library is a wrapper library for PHPs own &amp;quot;time()&amp;quot; function. With the use of this library, our aim was to isolate our system with the &amp;quot;system clock&amp;quot; which is used by the PHP's &amp;quot;time()&amp;quot; function. A separate wrapper for time lets us move time forward (future) or backwards (past) without changing the actual system time. This central library can be reset-ed to a different time and that time would be reflected in all of the application, without having to change any other component in the system or application.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Random: &amp;lt;/b&amp;gt;This library is the central library to generate random numbers and strings for the whole application. Using this library we can generate cryptographically random strings of any length. This function also produces random integers.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&amp;lt;h4&amp;gt;Need for Time and Randomness Library&amp;lt;/h4&amp;gt;&lt;br /&gt;
With time, developers often feel the need to change the system time - maybe for testing purpose or for different time-zones. Whatever is the case, developers find a hard time using normal PHP's &amp;quot;time()&amp;quot; function. To change time to some other time, they have to change system time, which is not only insecure, but will also affect many functions inside the host operating systems which heavily depend on time, such as Cron jobs and time-triggered events. This also is not recommended on main servers as this can corrupt other authentication servers such as &amp;quot;Kerberos&amp;quot;. Also it may give an attacker a window to launch some attacks to time-dependent functions. Thus, for all the reasons stated above, we strongly felt the need to generate a wrapper for the time, so that change of time within an application can be isolated and controlled. With this we mean that change in time in one application must not affect any other application or system outside the scope of the application.&lt;br /&gt;
&amp;lt;BR&amp;gt;&lt;br /&gt;
Similarly the need of randomness is crucial in an application. With random strings being so important in a secure application and because not having a separate function in PHP's library for generating a cryptographically secure random string of desired length, we decided to create a separate central library that can provide random strings of desired length. With this library the developers can create secure strings of desired length and can also generate a random integer within a desired range.&lt;/div&gt;</summary>
		<author><name>Rahul Chaudhary</name></author>	</entry>

	</feed>