Generating random string in a table 
Author Message
 Generating random string in a table
hello, I'm wondering if there are any easy ways to generate random
string/number in a table field. I'd like to generate a field called
"password" for a list of users in a table "tblUsers", I use "rand",
"getdate" (something like that) to generate the value but in return I find
that all users with the same passwords at the end. It seems the only way to
solve the problem is to use cursor but I'm just wondering if I miss
anything, thanks.

Samuel



Sat, 19 Feb 2005 21:58:55 GMT
 Generating random string in a table

Here is a method from Vyas' site:
http://vyaskn.tripod.com/code/password.txt

--
- Anith



Sat, 19 Feb 2005 22:05:29 GMT
 Generating random string in a table
There's also a useful tool at http://www.winguides.com/security/password.php



Quote:
> hello, I'm wondering if there are any easy ways to generate random
> string/number in a table field. I'd like to generate a field called
> "password" for a list of users in a table "tblUsers", I use "rand",
> "getdate" (something like that) to generate the value but in return I find
> that all users with the same passwords at the end. It seems the only way
to
> solve the problem is to use cursor but I'm just wondering if I miss
> anything, thanks.

> Samuel



Sat, 19 Feb 2005 22:11:18 GMT
 Generating random string in a table


Quote:
> hello, I'm wondering if there are any easy ways to generate random
> string/number in a table field. I'd like to generate a field called
> "password" for a list of users in a table "tblUsers", I use "rand",
> "getdate" (something like that) to generate the value but in return I find
> that all users with the same passwords at the end. It seems the only way
to
> solve the problem is to use cursor but I'm just wondering if I miss
> anything, thanks.

> Samuel

Youre doing this in an UPDATE (or INSERT) statement, right?

The call to rand(getdate()) will get evaluated before the update/insert
is executed, and will hence return the _same_ (random) value for
each row affected.

You must include some 'rowdependent number' into the calculation rand()
to get different values for each row.

Id-numbers are good for these kind of things. Note that you may have to
multiply it by some factor to get a resulting rand() big enough to really
make
a difference.

/johan



Sat, 19 Feb 2005 23:37:04 GMT
 Generating random string in a table

Quote:
> hello, I'm wondering if there are any easy ways to generate random
> string/number in a table field. I'd like to generate a field called
> "password" for a list of users in a table "tblUsers", I use "rand",
> "getdate" (something like that) to generate the value but in return I find
> that all users with the same passwords at the end. It seems the only way to
> solve the problem is to use cursor but I'm just wondering if I miss
> anything, thanks.

> Samuel

This is what I use

UPDATE tblUsers
SET password = cast(newid() as varchar(10))

newid() will return a random result, based on time and various other
things, it's quite a long string, so I've truncated it with a cast().

David Roussel



Sun, 20 Feb 2005 19:42:47 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. Generating a Unique Random string for PK

2. Generating a Unique Random string for PK

3. Generating random numbers mixed with strings

4. HELP, how to Generate random CHAR(6) string?

5. generating random strings

6. How to Generate True Random IDs?

7. EASY: SQL to generate a simple random number?

8. generating a random number

9. How to generate random numbers!

10. HOWTO: Generate Random Column ID as the Default

11. Generate random password as default value

12. Generating Random Numbers


 
Powered by phpBB® Forum Software