need linq code snippet to change password

I need a linq to sql code snippet that changes a user password.  I am not using membership provider

The arguments are

ChangePassword(User.Identity.Name, currentPassword, newPassword))

So check for valid user and password so if it is correct change to new password
Who is Participating?
Fernando SotoConnect With a Mentor RetiredCommented:
Hi ToString1;

This should do what you want.

// User to look up and change password
string userName = "User Name As String";
string currentPassword = "User Password";
// New password to replace old one.
string changePassword = "New Password";

// Create data context
DataClasses1DataContext usersDb = new DataClasses1DataContext();

// Get the user whos password is to be changed
USER user = (from u in usersDb.USER
             where u.Username == userName && u.Password == currentPassword
             select u).FirstOrDefault();

// Check to see if user is in the DB or not
if (user != null)
    // User was found, change the password
    user.Password = changePassword;
    // Save the new password to the DB
    // Username, password or both are incorrect
    Response.Write("Invalid Username, Password or both.");

Open in new window

Fernando SotoRetiredCommented:
Hi ToString1;

It would help to give the Database name, table names and columns names that are to be used and if ChangePassword is a call to a Stored Procedure or a function in your program.


ToString1Author Commented:

Table called USER

UserId.  Int
Username.  Varchar(100)
Password.  Nvarchar(255)
Email. Nvarchar(255)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.