Developer forum

Forum » Templates » Razor login error

Razor login error

Nuno Aguiar
Reply

Hi,

 

We are trying to perform a login in Razor but get an error. The login is performed, but we always get the error. Does anyone have any idea on how to solve this? We are using 8.4.1.3

 

Code:
if(str_password == obj_dataSet.Tables[0].Rows[0]["AccessUserPassword"].ToString() || str_password == Dynamicweb.Base.pwEncrypt(obj_dataSet.Tables[0].Rows[0]["AccessUserPassword"].ToString()))
{
    var security = new Dynamicweb.Security();
    We tried both ways:
    security.ExtranetLogin(str_username, str_password);
    security.ExtranetLogin(str_username, str_password, true);
}


Error:

System.ArgumentNullException: Value cannot be null.
Parameter name: value
   at System.Web.Caching.CacheEntry..ctor(String key, Object value, CacheDependency dependency, CacheItemRemovedCallback onRemovedHandler, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, Boolean isPublic)
   at System.Web.Caching.CacheInternal.DoInsert(Boolean isPublic, String key, Object value, CacheDependency dependencies, DateTime utcAbsoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, CacheItemRemovedCallback onRemoveCallback, Boolean replace)
   at Dynamicweb.eCommerce.Cart.Session.Add(String key, Object value)
   at Dynamicweb.eCommerce.Common.Context.LoadUserContextCarts()
   at Dynamicweb.Security.ExtranetLogin(String username, String password, Boolean onlyActive, Boolean impersonateUser, Int32 impersonateUserID)
   at Dynamicweb.Security.ExtranetLogin(String username, String password, Boolean onlyActive)
   at CompiledRazorTemplates.Dynamic.efccdaefeea.Execute()
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context)
   at RazorEngine.Razor.Parse[T](String razorTemplate, T model, String cacheName)
   at Dynamicweb.Rendering.Template.Output()

 

Best Regards,

Nuno


Replies

 
Mikkel Ricky
Reply

I have tried this and the login part itself works well with Razor (for me). Does regular login (using username and passwowrd fields) produce the samme error?

I'll ask around at HQ to see if we can find out what's going on.

Best regards,
Mikkel

 

 
Nuno Aguiar
Reply

Hi Mikkel,

 

Yes, standard login works well. We were trying to add a new login logic, submitting 2 fields, and after doing some extra validations, do the actual login, hence the code.

 

We are trying to avoid working in c#, compiling and having more dll's in the mix, just Razor "magic".

 

Nuno

 
Mikkel Ricky
Reply

We have found a bug and are investigating the cause.

You can add a try-catch(System.ArgumentNullException) block around the login code to work aorund the bug.

Best regards,
Mikkel

 
Kevin O''Driscoll
Reply

Has this bug been fixed from May 2014? Trying to do the same, what am I doing wrong? Normal login works fine

        private void ValidateAndLoginDynamicWeb(string username, string password)
        {
            Dynamicweb.Modules.UserManagement.User user = new Dynamicweb.Modules.UserManagement.User(username);
            // user.IsUserNameValid(); // Checks if the username is UNIQUE in the database!  Not if the UserName is a valid UserName
            // Enum e = new Dynamicweb.Modules.UserManagement.User.PermissionLevels();
            //.Authenticate(username, password, e); ?? why and how??

            string pWord = EncodePassword(password); // MD5 Hashed

                var security = new Security();
                security.ExtranetLogin(user.UserName, pWord, true);
                if(security.UserLoggedIn)
                { 
                    Response.Redirect(Request.Url.ToString());
                }

}

private string EncodePassword(string originalPassword)
        {
            //Declarations
            Byte[] originalBytes;
            Byte[] encodedBytes;
            MD5 md5;

            //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
            md5 = new MD5CryptoServiceProvider();
            originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
            encodedBytes = md5.ComputeHash(originalBytes);
            return BitConverter.ToString(encodedBytes).Replace("-","").ToLower().Trim();
        }

 
Nicolai Høeg Pedersen
Reply

Hi Kevin

No need to encrypt the password first - DW will do that check for you, so simply pass the password in clear text. Calling User management authenticate will not log the user in properly.

What error do you get?

Nicolai

 
Kevin O''Driscoll
Reply

Hi Nicolai. Yes I tried Authenticate(username, password, e); but it did not login properly and wasnt sure of the usage. (What is its usage?)

                var security = new Security();
                security.ExtranetLogin(username, password, true);
                if(security.UserLoggedIn)
                { 
                    Response.Redirect(Request.Url.ToString());
                }

Without pre-encrypting seemed to work. (We have set DW to Encrypt Passwords so I assumed we needed to do this.)

 

 

You must be logged in to post in the forum