English 中文(简体)
Can tlogin to my ownlogin page
原标题:Can t login to my own login page

我先天创建了我自己的日志,但当我试图通过点击提交纽特来签署时,它便跳出“渔获”的权利,而后者却不向阿明转移。 我看不出任何这方面的信息。 我也试图去除尝试和捕获物,并得出这一例外:“用户代码不交出InvalidOpration Exception”。

此处用我的标识方法:

public class LoginController : Controller
{
            public static byte[] lagHash(string innString)
    {
        var algoritm = System.Security.Cryptography.MD5.Create();
        byte[] data, utdata;
        data = System.Text.Encoding.ASCII.GetBytes(innString);
        utdata = algoritm.ComputeHash(data);
        return utdata;
    }

public ActionResult Login()
    {

        return View();
    }
    [HttpPost]
    public ActionResult Login(FormCollection innAdmin)
    {
        string Username = innAdmin["Username"];

        try
        {
            byte[] passwordArray;
            passwordArray = createHash(innAdmin["Password"]);

            var db = new Models.DataClass1DataContext();
            var Admin = (from s in db.Admins
                         where s.Username == Username &&
                         s.Password == passwordArray
                         select s).Single();
            if (Admin.Username == innAdmin["Username"])
            {
                return RedirectToAction("Admin", "Admin");
            }
            else
            {
                return View();
            }
        }
        catch (Exception wrong)
        {
            return View();
        }
    }

The Code for the aspx file:

<table>
    <tr>
        <td>Username :</td>
        <td>
            <input type = "text" name="Username" />
        </td>
    </tr>
    <tr>
        <td>Password :</td>
        <td>
            <input type = "password" name="Password" />
        </td>
    </tr>
    <tr>
        <td>
            <input type = "submit" value="Log In" />
        </td>
    </tr>

问题回答

看来,你需要把你的边际阵列转化为扼杀。 利用适当的编码和转换成体。

public static string ByteArrayToString(byte[] bytes, EncodingType encodingType) 
{ 
    System.Text.Encoding encoding=null; 
    switch (encodingType) 
    { 
        case EncodingType.ASCII: 
            encoding=new System.Text.ASCIIEncoding(); 
            break;    
        case EncodingType.Unicode: 
            encoding=new System.Text.UnicodeEncoding(); 
            break;    
        case EncodingType.UTF7: 
            encoding=new System.Text.UTF7Encoding(); 
            break;    
        case EncodingType.UTF8: 
            encoding=new System.Text.UTF8Encoding(); 
            break;    
    } 
    return encoding.GetString(bytes); 
} 

* EDIT * try the following:

var admin = (from s in db.Admins where s.Username == Username && s.Password == passwordArray select s).SingleOrDefault();
if (admin != null)
{
return RedirectToAction("Admin", "Admin");
}
else
{
return View();
}     

* EDIT 2 * That means your validation is failing. Try this:

var test = (from s in db.Admins where s.Username == Username select s).SingleOrDefault();
if (test != null)
{
   var test2 = test.Password;
}

place a breakpoint and examine the test object. It should not be null. Look at the retrieved password and compare it against the hashed one you are using. You are closing in now.

** EDIT 3 ** Well, then that means the problem is with your datastore. The username you are using to login just does not exist, therefore login can never succeed!





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签