473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problems with random password generation

Hello,

I am having some problems with these functions which are to be part of the
forgotten password system for a website. I am sure it is something simple
but I can't see it. I would be grateful for any help anyone could offer.

The plan is: The users forgets their password so they enter their email
address together with responses to some security questions (currently just
zip/postcode). A random password is generated and, providing the security
questions validate, is hashed and stored to the password field in the DB
user table. The new password is emailed to the user.

Here is the problem: If I let the code do the work I can not log the user in
using the generated password. However, if I bypass GeneratePassword by
substituting it with a password that was previously generated, and emailed,
by the code - so the line becomes: Dim ForgotPassword as String =
"Giz8q1hm" - everything works and the password validates when I log in using
it.

Here is the code:
Private Shared ReadOnly _allowedChars As String =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789"

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''
' GenerateForgotPassword
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''
Public Shared Function GenerateForgotPassword(ByVal EmailAddress As String,
ByVal PostCode As String) As Boolean
Dim moduleSettings As Configuration.ModuleSettings =
Configuration.ModuleConfig.GetSettings()
' Generate a random password
Dim ForgotPassword As String = GeneratePassword(8)
Dim hashRandomPassword As Byte() =
SitePrincipal.EncryptPassword(ForgotPassword)
' Store password to user table
Dim User As New Data.User(moduleSettings.ConnectionString)
If User.GenerateForgotPassword(EmailAddress, PostCode, hashRandomPassword)
Then
' Email password to user
Dim strMailBody As String
strMailBody = "Test Generate Password : " & ForgotPassword
ApplicationTools.SendMail("ad************@ntlworld .com",
"em***@adamcarpenter.co.uk", "Test Generate Password", strMailBody)
Return True
End If
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''
' Generate Password
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''
Private Shared Function GeneratePassword(ByVal length As Integer) As String
' Get random bytes from RNGCryptoServiceProvider
Dim randomBytes(length) As Byte
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(randomBytes)
' Convert bytes to characters from allowed characters
Dim chars(length) As Char
Dim allowedCharCount = _allowedChars.Length
Dim i As Integer
For i = 0 To length - 1
chars(i) = _allowedChars.Chars(randomBytes(i) Mod allowedCharCount)
Next
Return New String(chars)
End Function

Any ideas what could be wrong? Many thanks in advance.

Adam
Nov 20 '05 #1
0 1185

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DJTB | last post by:
zodb-dev@zope.org] Hi, I'm having problems storing large amounts of objects in a ZODB. After committing changes to the database, elements are not cleared from memory. Since the number of...
7
by: Ioannis Vranos | last post by:
I want to create some random numbers for encryption purposes, and i wonder if the following scheme makes it more hard to guess the underneath number generation pattern, than the plain use of...
13
by: Roy Gourgi | last post by:
Hi, How do I invoke the random number generator that was suggested by a few people. Ideally, what I would like to do is to instantiate the random no. generator with a seed value that does not...
24
by: NoName | last post by:
Perl: @char=("A".."Z","a".."z",0..9); do{print join("",@char)}while(<>); !!generate passwords untill U press ctrl-z Python (from CookBook):
2
by: RYAN1214 | last post by:
How can I use this random password code, and then insert the password into email which is sent to the user after the registration has been finished? thx <html> <head> <title>Javascript:...
0
by: sweatha | last post by:
Hi Friends I have designed a form with a label box named 'Label30' and text box named 'TextBox21'. Then I have generated the random number in the label box using the coding in form load event as ...
16
by: jason.cipriani | last post by:
I am looking for a random number generator implementation with the following requirements: - Thread-safe, re-entrant. - Produces consistently reproducible sequences of psuedo-random numbers...
17
by: almurph | last post by:
Hi, Hope you can help me with this one. I am trying to create random number between 0 and 1 inclusive of cryptographiuc quality. The problems is though - I don't know how! Here is what I have so...
3
by: divyac | last post by:
I want to generate password randomly and send to mysql database using PHP..i have got the following function for generating password but doesn't know how to incorporate in my registration form and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.