R
R
rusgayfer2018-03-05 00:54:03
PHP
rusgayfer, 2018-03-05 00:54:03

What is the correct and easiest way to generate a key?

I do the key generation for checks in the following way:

// Генерируем ключ
$symbol=array('0','1','2','3','4','5','6','7','8','9','A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','Q','q','R','r','S','s','T','t','U','u','V','v','W','w','X','x','Y','y','Z','z');
for ($i=0; $i<20; $i++): 
$rand_symbol=$symbol[rand(0,61)]; 
$key=$key.$rand_symbol;
endfor;
echo $key;

Am I doing the right thing? Or is there something easier and different? How to make it look more like a VK token

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Sisyukin, 2018-03-05
@Caarl

Read about cryptographic functions php.net/manual/ru/refs.crypto.php
The way you generate a token is not very secure
For example take a look at open ssl
php.net/manual/ru/function.openssl-encrypt.php

K
Kirill Nesmeyanov, 2018-03-05
@SerafimArts

\base64_encode(\random_bytes(...));
Isn't it easier?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question