HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0HOW TO: Programmatically Create New UserHOW TO: Programmatically Create New User
Previous
 
Next
New Post
6/8/2007 11:29 AM
 

And YES we are using that obviex password generator. We needed it back in 2005 and it just stayed in the app even after we've moved on to 4.5+ version.

Honestly, I find that DNN random password (I don't mean the code - didn't even look at it since I already have something, right?) to be a little too much for a regular user to look at :) - I mean all the special characters... I think alphanumeric with mixed capitalization is just fine. At least until the first login.


Vitaly Kozadayev
Principal
Viva Portals, L.L.C.
 
New Post
6/11/2007 4:55 AM
 

vitkoz wrote

And YES we are using that obviex password generator. We needed it back in 2005 and it just stayed in the app even after we've moved on to 4.5+ version.

Honestly, I find that DNN random password (I don't mean the code - didn't even look at it since I already have something, right?) to be a little too much for a regular user to look at :) - I mean all the special characters... I think alphanumeric with mixed capitalization is just fine. At least until the first login.

I agree with your assessment of the password generator.  The generated password is not at all even close to being user-friendly for the average Internet "surfer".  And a quick browse through the source didn't immediately show me a way to customize it the same way you can for most of the other configurable settings (whitespace filter, url rewrite, etc.).

In reference to your other posts, that puts me back on the drawing board for the other issue.  :)  Thanks!


These are my personal opinions and don't necessarily represent the views and opinions of DotNetNuke Corporation.
Will Strohl
Media Module Team Lead, User Groups Team Lead
Sales Engineer, DotNetNuke Corporation

DotNetNuke Blog | Find a DNN User Group | Media Module
Twitter: @WillStrohl LinkedIn: Will Strohl on LinkedIn

 
New Post
6/11/2007 8:04 AM
 

Hahaha!!!  Let's revert to Occam's Razor for a moment...

We all (me first) overlooked the most important thing in this user creation process.  I was passing in the portal ID, but I was not properly appending it to the UserInfo properties...  I know how I overlooked it...  I saw the "PortalID" reference in the Profile initialization line and made an incorrect assumption while proofing the code.  I didn't put the "PortalID" into the UserInfo.PortalID property of the UserInfo object.

Once I changed that, everything is working as expected with profile properties being created, the user being created and my custom code being properly called and executed. 

Whew!!!  That was a doozy...  Sorry to waste everyone's time.  :)

Here is the updated code for anyone that might want or need to use it (tested for DNN v 4.05.01 through v4.05.03):

Public Function CreateNewUser(ByVal strUsername As String, ByVal strFirstName As String, ByVal strLastName As String, _
     ByVal strEmailAddress As String, ByVal blnMembershipApproved As Boolean) As DotNetNuke.Security.Membership.UserCreateStatus
     '===============================================================================
     '
     ' BEGIN VALIDATION
     '
     '===============================================================================
     ' preliminary check to be sure that the fields are filled in
     ' (cannot have empty values)
     If String.IsNullOrEmpty(strUsername) Then _
          Throw New NullReferenceException("The USERNAME variable for CreateNewUser() cannot be empty.")
     If String.IsNullOrEmpty(strFirstName) Then _
          Throw New NullReferenceException("The FIRSTNAME variable for CreateNewUser() cannot be empty.")
     If String.IsNullOrEmpty(strLastName) Then _
          Throw New NullReferenceException("The LASTNAME variable for CreateNewUser() cannot be empty.")
     If String.IsNullOrEmpty(strEmailAddress) Then _
          Throw New NullReferenceException("The EMAILADDRESS variable for CreateNewUser() cannot be empty.")
     ' validate the e-mail address format
     If Not MYNAMESPACE.Common.Utilities.RegExLibrary.ValidateEmailFormat(strEmailAddress) Then _
          Throw New Exception("The e-mail address was in an invalid format")
     '===============================================================================
     '
     ' END VALIDATION
     '
     '===============================================================================
     ' create a new user instance and populate it
     Me.User = New DotNetNuke.Entities.Users.UserInfo
     With Me.User
          .Profile.InitialiseProfile(PortalSettings.PortalId)
          .AffiliateID = -1
          .DisplayName = String.Concat(strFirstName, " ", strLastName)
          .Email = strEmailAddress
          .FirstName = strFirstName
          .IsSuperUser = False
          .Membership.Approved = blnMembershipApproved
          .Membership.CreatedDate = DateTime.Now
          .Membership.Email = strEmailAddress
          '.Membership.Password = DotNetNuke.Entities.Users.UserController.GeneratePassword
          .Membership.Password = MYNAMESPACE.Security.PasswordGenerator.Generate(8, 10)
          .Membership.UpdatePassword = True
          .Membership.Username = strUsername
          .PortalID = PortalSettings.PortalId
          .Username = strUsername
          .Profile.FirstName = strFirstName
          .Profile.LastName = strLastName
          .Profile.PreferredLocale = Me.PortalSettings.DefaultLanguage
          .Profile.TimeZone = Me.PortalSettings.TimeZoneOffset
     End With
     ' I am now handling this in the customized profile/membership provider(s)
     ' Set the Approved status based on the Portal Settings
     'If Me.PortalSettings.UserRegistration = DotNetNuke.Common.Globals.PortalRegistrationType.PublicRegistration Then
     '    Me.User.Membership.Approved = True
     'Else
     '    Me.User.Membership.Approved = False
     'End If
     ' attempt to create the DNN user
     Dim objStatus As UserCreateStatus = Users.UserController.CreateUser(Me.User)
     ' set-up the arguments for the status of the user creation
     Dim args As Modules.UserUserControlBase.UserCreatedEventArgs
     If objStatus = UserCreateStatus.Success Then
          args = New Modules.UserUserControlBase.UserCreatedEventArgs(Me.User)
          args.Notify = True
     Else    ' registration error
          args = New Modules.UserUserControlBase.UserCreatedEventArgs(Nothing)
          args.Notify = False
     End If
     args.CreateStatus = objStatus
     ' perform some DNN logic
     Me.UserCreateCompleted(args)
     Return objStatus
End Function 

These are my personal opinions and don't necessarily represent the views and opinions of DotNetNuke Corporation.
Will Strohl
Media Module Team Lead, User Groups Team Lead
Sales Engineer, DotNetNuke Corporation

DotNetNuke Blog | Find a DNN User Group | Media Module
Twitter: @WillStrohl LinkedIn: Will Strohl on LinkedIn

 
New Post
6/11/2007 10:16 AM
 

Wow... one of those things where no matter how hard you scrutinize it, your eyes just glaze past the problem and don't take notice to it.  I was wracking my brain trying to figure this out for you and don't know if I ever would have noticed that.  Glad you were able to resolve the issue!

As far as password generation goes, this link (http://www.codeproject.com/dotnet/CryptoPasswordGenerator.asp) contains details to what I have been using and it is configurable enough to make some "easy" passwords.  If you perform a "password generator" search there on the codeproject, you'll find several different methods of varying strength.  Give it a whirl.


-- Jon Seeley
DotNetNuke Modules
Custom DotNetNuke and .NET Development
http://www.seeleyware.com
 
New Post
7/9/2007 12:08 AM
 

Hi,

I've been trying to test your example in my DNN 4.5.3 local install but I'm not able to create a user.  There must be something I'm missing.  Below is my code if anyone would be so kind as to point me in the right direction.

Thanks in advance.

Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Entities.Modules.Actions
Imports DotNetNuke.Entities.Profile
Imports DotNetNuke.Security.Profile
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Mail
Imports DotNetNuke.Security.Membership
Imports DotNetNuke.UI.Skins.Controls.ModuleMessage
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.UI.WebControls

Namespace MyNameSpace

    Partial Class ManageUsers
        Inherits UserModuleBase
        Implements IActionable

#Region "Event Handlers"

        ' Page_Load runs when the control is loaded
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim strUsername, strFirstName, strLastName, strEmailAddress As String
            Dim blnMembershipApproved As Boolean

            strUsername = Request.QueryString("e")
            strFirstName = Request.QueryString("fn")
            strLastName = Request.QueryString("ln")
            strEmailAddress = Request.QueryString("e")
            blnMembershipApproved = True

            Try
                CreateNewUser(strUsername, strFirstName, strLastName, strEmailAddress, blnMembershipApproved)
             Catch ex As Exception    'Module failed to load
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub

        Public Function CreateNewUser(ByVal strUsername As String, ByVal strFirstName As String, ByVal strLastName As String, _
             ByVal strEmailAddress As String, ByVal blnMembershipApproved As Boolean) As DotNetNuke.Security.Membership.UserCreateStatus
            '===============================================================================
            '
            ' BEGIN VALIDATION
            '
            '===============================================================================
            ' preliminary check to be sure that the fields are filled in
            ' (cannot have empty values)

            If String.IsNullOrEmpty(strUsername) Then _
                 Throw New NullReferenceException("The USERNAME variable for CreateNewUser() cannot be empty.")
            If String.IsNullOrEmpty(strFirstName) Then _
                 Throw New NullReferenceException("The FIRSTNAME variable for CreateNewUser() cannot be empty.")
            If String.IsNullOrEmpty(strLastName) Then _
                 Throw New NullReferenceException("The LASTNAME variable for CreateNewUser() cannot be empty.")
            If String.IsNullOrEmpty(strEmailAddress) Then _
                 Throw New NullReferenceException("The EMAILADDRESS variable for CreateNewUser() cannot be empty.")
            ' validate the e-mail address format
            'If Not MyNameSpace.Common.Utilities.RegExLibrary.ValidateEmailFormat(strEmailAddress) Then _
            '     Throw New Exception("The e-mail address was in an invalid format")
            '===============================================================================
            '
            ' END VALIDATION
            '
            '===============================================================================
            ' create a new user instance and populate it
            Me.User = New DotNetNuke.Entities.Users.UserInfo
            With Me.User
                .Profile.InitialiseProfile(PortalSettings.PortalId)
                .AffiliateID = -1
                .DisplayName = String.Concat(strFirstName, " ", strLastName)
                .Email = strEmailAddress
                .FirstName = strFirstName
                .IsSuperUser = False
                .Membership.Approved = blnMembershipApproved
                .Membership.CreatedDate = DateTime.Now
                .Membership.Email = strEmailAddress
                .Membership.Password = DotNetNuke.Entities.Users.UserController.GeneratePassword
                '.Membership.Password = MyNameSpace.Security.PasswordGenerator.Generate(8, 10)
                .Membership.UpdatePassword = True
                .Membership.Username = strUsername
                .PortalID = PortalSettings.PortalId
                .Username = strUsername
                .Profile.FirstName = strFirstName
                .Profile.LastName = strLastName
                .Profile.PreferredLocale = Me.PortalSettings.DefaultLanguage
                .Profile.TimeZone = Me.PortalSettings.TimeZoneOffset
            End With
            ' I am now handling this in the customized profile/membership provider(s)
            ' Set the Approved status based on the Portal Settings
            'If Me.PortalSettings.UserRegistration = DotNetNuke.Common.Globals.PortalRegistrationType.PublicRegistration Then
            'Me.User.Membership.Approved = True
            'Else
            '    Me.User.Membership.Approved = False
            'End If
            ' attempt to create the DNN user
            Dim objStatus As UserCreateStatus = DotNetNuke.Entities.Users.UserController.CreateUser(Me.User)
            ' set-up the arguments for the status of the user creation
            Dim e As DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs

            If objStatus = UserCreateStatus.Success Then
                e = New DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs(Me.User)
                e.Notify = True
                Response.Write(" objStatus = UserCreateStatus.Success ")
            Else    ' registration error
                e = New DotNetNuke.Entities.Modules.UserUserControlBase.UserCreatedEventArgs(Nothing)
                e.Notify = False
                Response.Write("NOT objStatus = UserCreateStatus.Success ")
            End If

            e.CreateStatus = objStatus
            ' perform some DNN logic
            Me.UserCreateCompleted(e)
            Return objStatus
        End Function

        Private Sub UserCreateCompleted(ByVal e As UserUserControlBase.UserCreatedEventArgs)
            Dim strMessage As String = ""

            Try
                If e.CreateStatus = UserCreateStatus.Success Then
                    Dim objUser As UserInfo = e.NewUser

                    'If IsRegister Then
                    ' send notification to portal administrator of new user registration
                    'Mail.SendMail(User, MessageType.UserRegistrationAdmin, PortalSettings)

                Else
                    'If e.Notify Then
                    '    'Send Notification to User
                    '    If PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
                    '        Mail.SendMail(User, MessageType.UserRegistrationVerified, PortalSettings)
                    '    Else
                    'Mail.SendMail(User, MessageType.UserRegistrationPublic, PortalSettings)
                    'End If
                    '    End If
                End If

                'Else
                'End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region

#Region "Optional Interfaces"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Gets the ModuleActions for this ModuleControl
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        '''  [cnurse] 3/01/2006 created
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Public ReadOnly Property ModuleActions() As ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New ModuleActionCollection
                If (IsAdminTab Or IsHostTab) And (Me.ModuleId > -1) Then

                    If Not AddUser Then
                        Actions.Add(GetNextActionID, Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "add.gif", EditUrl(), False, SecurityAccessLevel.Admin, True, False)

                        If ProfileProviderConfig.CanEditProviderProperties Then
                            Actions.Add(GetNextActionID, Localization.GetString("ManageProfile.Action", LocalResourceFile), ModuleActionType.AddContent, "", "icon_profile_16px.gif", EditUrl("ManageProfile"), False, SecurityAccessLevel.Admin, True, False)
                        End If
                    End If

                    'Actions.Add(GetNextActionID, Localization.GetString("Cancel.Action", LocalResourceFile), ModuleActionType.AddContent, "", "lt.gif", ReturnUrl, False, SecurityAccessLevel.Admin, True, False)
                End If
                Return Actions
            End Get
        End Property

#End Region

    End Class

End Namespace

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0HOW TO: Programmatically Create New UserHOW TO: Programmatically Create New User


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

Attend A Webinar
Free Demo Site
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me
Have Someone Contact Me
DotNetNuke Store

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

r2integrated
Telerik JustCode Free
Exact Target Exec Alert

DotNetNuke Scoop!

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates the DotNetNuke Store where users purchase third party apps for the platform.