public static bool CheckLogin(string Username, string Password, bool AutoLogin)
{
bool LoginSuccessful;
// Trim inputs and verify lengths
Username = Username.Trim();
Password = Password.Trim().ToLower();
// Get the associated user records
DataClassesDataContext db = new DataClassesDataContext();
var q = (from User in db.tblForumAuthors where User.Username == Username select new
{
User.Password,
User.Salt,
User.Username,
User.Author_ID,
User.User_code,
User.Active,
User.Login_attempt,
User.Last_visit,
}).SingleOrDefault();
// Invalid details passed
if (q == null)
{
LoginSuccessful = false;
}
else
{
// Increment login attempts counter
int LoginAttempts = q.Login_attempt;
LoginAttempts++;
// Encrypt the password
string HashedPassword = GetSha1(Password + q.Salt);
// Check passwords match
if (q.Password == HashedPassword)
{
LoginSuccessful = true;
}
else
{
LoginSuccessful = false;
// Increment login attempts
q.Login_attempt = LoginAttempts;
db.SubmitChanges();
}
}
return LoginSuccessful;
}
}
On the line
q.Login_attempt = LoginAttempts;
I get:
Error 50 Property or indexer 'AnonymousType#1.Login_attempt' cannot be assigned to -- it is read only C:\inetpub\wwwroot\ScirraNew\App_Code\Login.cs 82 17 C:\...\ScirraNew\
Can anyone show me how I can update this counter in the record please?
You need to just select the whole User item if you want to edit it. Get rid of your whole “Select New” clause.