Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedProblem in membershipProblem in membership
Previous
 
Next
New Post
4/21/2013 3:50 PM
 

We are building a mobile application which integrate through the DNN.

The mobile application uses ASP.net webservice which connect to the DNN Modules, in the mobile application there exist two options

the first option:

- the registration screen

which create new user in the DNN Module,  the problem is that in the ASP.net Web service the webmethod that is reponsible for creating the new user, it connect to the DNN database and insert new record in the tables (membership tables)

 

- aspnet_Membership

-aspnet_Users

-Users                                                                                                                                                           

 

the problem is that when insering new users in these table specially

([aspnet_Membership]) using ASP.net code and Linq.sql Framework

 

for these fields

 

,[Password]

,[PasswordFormat]

,[PasswordSalt]

 

 

we sypher the user password with Trible DES Algrithem 

we creating class to generate salt and encrypt and decrypt passwords

public class NetFourMembershipProvider : SqlMembershipProvider

{

public string GenerateSalt()

{

var buf = new byte[20];

(new RNGCryptoServiceProvider()).GetBytes(buf);

return Convert.ToBase64String(buf);

}

public string EncodePassword(byte passFormat, string passtext, string passwordSalt)

{

if (passFormat.Equals(0)) // passwordFormat="Clear" (0)

return passtext;

else

{

byte[] bytePASS = Encoding.Unicode.GetBytes(passtext);

byte[] byteSALT = Convert.FromBase64String(passwordSalt);

byte[] byteRESULT = new byte[byteSALT.Length + bytePASS.Length + 1];

System.Buffer.BlockCopy(byteSALT, 0, byteRESULT, 0, byteSALT.Length);

System.Buffer.BlockCopy(bytePASS, 0, byteRESULT, byteSALT.Length, bytePASS.Length);

if (passFormat.Equals(1)) // passwordFormat="Hashed" (1)

{

HashAlgorithm ha = HashAlgorithm.Create(Membership.HashAlgorithmType);

return (Convert.ToBase64String(ha.ComputeHash(byteRESULT)));

}

else // passwordFormat="Encrypted" (2)

{

return (Convert.ToBase64String(this.EncryptPassword(byteRESULT)));

}

}

}

public string GetClearTextPassword(string encryptedPwd)

{

byte[] encodedPassword = Convert.FromBase64String(encryptedPwd);

byte[] bytes = this.DecryptPassword(encodedPassword);

if (bytes == null)

{

return null;

}

return Encoding.Unicode.GetString(bytes, 0x10, bytes.Length - 0x10).Substring(0,Encoding.Unicode.GetString(bytes, 0x10, bytes.Length - 0x10).Length - 1);

}

public new byte[] EncryptPassword(byte[] password)

{

return base.EncryptPassword(password);

}

}

 

and adding in web.config file the sypher key

 

 at app setting section we add

<add key="EncryptKey" value="42441B48BCA3F15B2353E426BC2C9111680E09E8"/>

 

at the system.web secton we add

 

<machineKey validationKey="42441B48BCA3F15B2353E426BC2C9111680E09E8" decryptionKey="00B3BAE82FEF44753E95AE088CCDB5E75C0F3BB1E58DEC2A" decryption="3DES" validation="SHA1" />

 

and the code for the register web servce is

 

try

{

string Email = Request.QueryString["Email"];

string UserName = Request.QueryString["UserName"];

string MobileNo = Request.QueryString["MobileNo"];

string FirstName = Request.QueryString["FirstName"];

string LastName = Request.QueryString["LastName"];

string password = Request.QueryString["Password"];

string salt = "35wj1+r/Dr6RYjBbIRhWeQ==";

NetFourMembershipProvider decriptor = new NetFourMembershipProvider();

string encryptedpassword = decriptor.EncodePassword(2, password, salt);

ORMDataContext myContext = new ORMDataContext();

int userCount = (from user in myContext.Users

where user.Username == UserName

select user.UserID).Count();

CustomUser myUser = new CustomUser();

if (userCount == 0)

{

aspnet_User membership_user = new aspnet_User();

membership_user.ApplicationId = Guid.Parse("4985C01A-3338-49C9-AC39-DC5934D5ED7A");

membership_user.UserName = UserName;

membership_user.LoweredUserName = UserName.ToLower();

membership_user.LastActivityDate = DateTime.Now;

membership_user.IsAnonymous = false;

membership_user.MobileAlias = MobileNo;

membership_user.UserId = Guid.NewGuid();

myContext.aspnet_Users.InsertOnSubmit(membership_user);

myContext.SubmitChanges();

aspnet_Membership membership = new aspnet_Membership();

Guid appID = Guid.Parse("4985C01A-3338-49C9-AC39-DC5934D5ED7A");

membership.ApplicationId = appID;

membership.CreateDate = DateTime.Now;

membership.Email = Email;

membership.FailedPasswordAnswerAttemptCount = 0;

membership.FailedPasswordAnswerAttemptWindowStart = DateTime.Now;

membership.FailedPasswordAttemptCount = 0;

membership.FailedPasswordAttemptWindowStart = DateTime.Now;

membership.IsApproved = true;

membership.IsLockedOut = true;

membership.LastLockoutDate = DateTime.Now;

membership.LastLoginDate = DateTime.Now;

membership.LastPasswordChangedDate = DateTime.Now;

membership.LoweredEmail = Email.ToLower();

membership.MobilePIN = "";

membership.Password = encryptedpassword;

membership.PasswordAnswer = "";

membership.PasswordFormat = 2;

membership.PasswordQuestion = "";

membership.PasswordSalt = salt;

membership.UserId = membership_user.UserId;

myContext.aspnet_Memberships.InsertOnSubmit(membership);

myContext.SubmitChanges();

Borsa_Ws.User user = new User();

user.Username = UserName;

user.CreatedOnDate = DateTime.Now;

user.DisplayName = UserName;

user.Email = Email;

user.FirstName = FirstName;

user.LastName = LastName;

user.UpdatePassword = false;

user.LastModifiedByUserID = -1;

user.IsSuperUser = false;

myContext.Users.InsertOnSubmit(user);

myContext.SubmitChanges();

Borsa_Ws.UserRole user_role1 = new Borsa_Ws.UserRole();

user_role1.UserID = user.UserID;

user_role1.RoleID = 1;

Borsa_Ws.UserRole user_role2 = new Borsa_Ws.UserRole();

user_role2.UserID = user.UserID;

user_role2.RoleID = 2;

myContext.UserRoles.InsertOnSubmit(user_role1);

myContext.UserRoles.InsertOnSubmit(user_role2);

myContext.SubmitChanges();

myUser.Roles = new int[] { 1, 2 };

myUser.Logged = "1";

myUser.UserID = user.UserID.ToString();

}

else

{

myUser.Logged = "0";

}

JavaScriptSerializer searlizer = new JavaScriptSerializer();

Response.Clear();

Response.ContentType = "application/json; charset=utf-8";

Response.Write(searlizer.Serialize(myUser));

Response.End();

}

catch

{

}

 

wehen we come to the DNN web site and trying to login we the new inserted data

the DNN refuse the login

 

so could you  tell me what is wrong with my code

 

thanks
 
New Post
4/22/2013 1:45 AM
 
Hi
You said the web service method is connecting to dnn module, then in order to registering user why dont u use the dnn CreateUser() of the UserController class for registering user. Instead of inserting record for user directly into database tables use the api provided by dnn.

Thanks,
Sunil Kumar [ DNN Developer, Mindfire Solutions,India ]
 
New Post
4/22/2013 5:19 AM
 
but  we use Asp.net code and the DNN classes not exist in the code
we use regular webservice we interact directly with the DataBase of the Dnn
so the CreateUser method did't exist in the code
 
New Post
4/25/2013 7:54 AM
 
Hi,

But you can add the reference DotNetNuke.dll & DotNetNuke.Web.dll to your web service which will help you in using dnn api to create user as sunil said.

Thanks,
Avinash Kumar
Mindfire Solutions,India
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedProblem in membershipProblem in membership


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, 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 DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out