For generating password or password salt or random password in forget password case we have to create a password in every situation.
For doing that we write code, but in this case, there may be a chance that password gets repeated which is not a good thing.
We will use GUID Global Unique identifier for generating passwords.
Public Function RegisterUser(user As User) As UserResponse
Dim userResponse As New UserResponse()
Dim result As Integer = -1
Dim accessToken As String = Guid.NewGuid().ToString()
Try
Using sqlConnection As New SqlConnection(ConnectionString)
Dim parameterList As New List(Of SqlParameter)()
parameterList.Add(New SqlParameter("@FirstName", user.FirstName))
parameterList.Add(New SqlParameter("@LastName", user.LastName))
parameterList.Add(New SqlParameter("@JobRoleID", user.JobRoleId))
parameterList.Add(New SqlParameter("@Email", user.Email))
parameterList.Add(New SqlParameter("@CompanyID", user.CompanyId))
parameterList.Add(New SqlParameter("@Password", user.Password))
parameterList.Add(New SqlParameter("@PasswordSalt", Guid.NewGuid().ToString()))
parameterList.Add(New SqlParameter("@AccessToken", accessToken))
parameterList.Add(New SqlParameter("@DeviceUUID", If([String].IsNullOrEmpty(user.DeviceId), [String].Empty, user.DeviceId)))
parameterList.Add(New SqlParameter("@DeviceType", If([String].IsNullOrEmpty(user.DeviceType), [String].Empty, user.DeviceType)))
parameterList.Add(New SqlParameter("@CreatedDate", System.DateTime.Now))
parameterList.Add(New SqlParameter("@IsDeleted", False))
parameterList.Add(New SqlParameter("@DeletedDate", System.DBNull.Value))
If sqlConnection.State = ConnectionState.Closed Then
sqlConnection.Open()
End If
result = Convert.ToInt32(BaseRepository.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "uspRegisterUser", parameterList.ToArray()))
Select Case result
Case 1
userResponse.Status = True
userResponse.Message = "User successfully registered."
user.AccessToken = accessToken
Exit Select
Case 2
userResponse.Status = False
userResponse.Message = "Email already exists."
Exit Select
Case Else
userResponse.Status = False
userResponse.Message = "Registration failed."
Exit Select
End Select
End Using
Catch ex As SqlException
Logger.LogException(ex)
userResponse.Status = False
userResponse.Message = "Error occurred while registering a user."
End Try
user.Password = Nothing 'Removing password in Response
userResponse.data = user
Return userResponse
End Function
In this case password salt is generated by using GUID
0 Comment(s)