Search code examples
asp.nett-sqlaspnetdb

How can I mass generate Usernames, Passwords, and simple profile info to load into ASPNETDB?


I have an existing database with an accountnumber. I want to create a script that will take that column as input and generate for each accountnumber a username/password/profile entry.

The profile entry would be the original account number.

So, for example assume I use accountnumber for user/pass as well...

This is what I Logically want to do

insert into ASPNETDB Select accountnumber, accountnumber as UserName, accountnumber as Password, accountnumber as profileentry from table1

I know that creating 1 user requires the use of some stored procs, that's why I'm not sure how to do this.


Solution

  • Here it is, I just reread the MS documentation and just went for it. This sets up a user account and generates a key profile value for each record.

    declare @PPID NVARCHAR(20)
    declare @salt NVARCHAR(500)
    declare @stupid NVARCHAR(500)
    declare @UserId uniqueidentifier
    declare cur CURSOR LOCAL for 
    select PPID from webData..table where PPID is not null
    
    open cur 
    
    fetch next from cur into @PPID
    
    while @@FETCH_STATUS = 0 BEGIN 
    set @salt = @PPID + @PPID 
    set @stupid = 'TangiblePropertyId:S: 0:'  + CONVERT(VARCHAR(10),LEN(@PPID))
        --execute your sproc on each row 
       exec [aspnetdb].[dbo].[aspnet_Membership_CreateUser] '/',
      @PPID
      ,@PPID
      ,@PPID
      ,@salt
      ,null
      ,null
      ,1
      ,'01/01/2011'
      ,DEFAULT
      ,DEFAULT
      ,DEFAULT
      ,@UserID
    
        exec dbo.aspnet_UsersInRoles_AddUsersToRoles '/',@PPID,'TaxPayer','01/01/2011'
    EXECUTE  [aspnetdb].[dbo].[aspnet_Profile_SetProperties]  '/' , @stupid ,@PPID  ,''  ,@PPID  ,false  ,'01/01/2011'
    
    PRINT @stupid
    
        fetch next from cur into @PPID 
    END 
    
    close cur 
    deallocate cur