Hi, i’m new here I hope you all doin fine! I developed a lot of Php web site in the pass, but im not really great with js.
Here what i want to do and been tryin the last 2 days…
I want to add a Random 3 to 6 digits Id user when a member register in Wix member
I had to put a secret box in the form because it wont work?
function getRandomInRange(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomString() {
return Math.random().toString(36).substr(2, 8);
}
$w.onReady(function () {
$w(‘#button6’).onClick(() => {
$w(‘#input10’).value = getRandomInRange(0, 99999).toString();
});
});
wixData
.query(“Members/FullData”)
.find()
.then((results) => {
// handle the results
});
the value in the fulldata is “IdP”
but now can i call a query to verify that the random IdP made does’nt already exist or he got to random another number and verify it.
is it possible to do this code? I would be able in Php but i’m not familiar with Velo
Or do I have to make a new “collection” to add the _id of the member and the new generated random Idp to compare…
I’m really lost with that,
Hi, @Joe_Beaupre !!
Hello, and welcome to the Wix Studio Forum! 
First, a fundamental question—each member in the Wix Members collection is already assigned a unique ID (which is hidden by default). Would that not work for your use case? However, keep in mind that this ID is not a purely numeric random string like the one you’re generating; it includes letters as well (likely a UUID). 
Yes but i would like to create a 3 to 5 digits ID to people can acces to a member page with this Id. I would like to assign a smaller Id to each member and people can acces to their page by entering that 5 digit id. because the assigned unique ID is really too long to be enter manually.
Personally, I think it would be better to create a new collection and store the data there. If you also need data from the “Members/FullData” collection, you could use a reference field within the new collection to link to the values in “Members/FullData” (probably). 
There is something important to keep in mind.
The function you’re using to generate the random string relies on Math.random()
, right? The randomness produced by Math.random()
is not considered highly secure (as it can be predicted), so it’s best to avoid using it for purposes like password generation.
Additionally, you should avoid generating random values on the frontend. This is because, if done in the browser, the random value generation algorithm is exposed, making it easier for someone to analyze and exploit.
For more secure random value generation, it’s better to generate the values on Wix’s backend (server-side) using a method other than Math.random()
and then return them to the frontend. If you want to learn about more secure ways to generate random values, you might want to ask ChatGPT for recommendations. 