Jump to content

random_bytes usage in email


Recommended Posts

I would like to create a a random number with random_bytes(). Can I just store the random_bytes output in the database field?

Is that for instance more secure?

And, regarding to sending it by email, what is the advantage above sending a code like uniqid() or md5($_POST['var'] + microtime() ?

 

I see the screen output is a bit uncommon (with ? in a diamond ) does that have to do with the encryption? And is that the reason why reason bin2hex is used to decrypt?

 

this is the code I would like to use:

	<html>
	<center>
	<br><br><br>
	the output  of the function random_bytes is: 
	<br><br>
	<?php  

	$num = random_bytes(15);
	echo '<br><br>' . $num ;
	echo '<br><br> var dump of random_bytes with bin2hex: ' ;

	echo bin2hex($num);

	?>



	</center></html>
Link to post
Share on other sites

Is that for instance more secure?

More secure than what?

 

And, regarding to sending it by email, what is the advantage above sending a code like uniqid() or md5($_POST['var'] + microtime() ?

What's the purpose? What are you using it for?

 

I see the screen output is a bit uncommon (with ? in a diamond ) does that have to do with the encryption?

Nothing is encrypted, you're just producing random bytes. Each byte can be one of 256 values. Not all of those bytes represent printable characters, so you're seeing what happens when you try to print a non-printable character. I don't know what your purpose is, but you can use base64_encode to change the encoding of the bytes to base64 which will contain only printable characters, and you can decode to get the original bytes back. But, like I said, I don't know what you're trying to do so I can't really suggest anything.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...