Invalid length for a Base-64 array

Asked by At

I have some lines of code where I get the error

Invalid length for a Base-64 array

This code is written for login page:

int user = 0;

UserDT = UserAdapter.Select();

for (int i = 0; i < UserDT.Rows.Count; i++)
    byte[] bb = Convert.FromBase64String(UserDT.Rows[i]["Password"].ToString());
    string getpass = System.Text.ASCIIEncoding.ASCII.GetString(bb);

    if (txtusername.Text == UserDT.Rows[i]["UserName"].ToString() && txtpassword.Text == getpass.ToString())
        userid =Convert.ToInt32(UserDT.Rows[i]["ID"].ToString());
        uname = UserDT.Rows[i]["UserName"].ToString();
        user = 1;

1 Answers

Windsting On

As you didn't provide the value that cause your error,

so check the document of the method FromBase64String

there is something about length:


The length of s, ignoring white-space characters, is not zero or a multiple of 4.

so just check the length of your parameter for FromBase64String.