Solved

need linq code snippet to change password

Posted on 2010-09-13
3
509 Views
Last Modified: 2013-11-11

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
0
Comment
Question by:ToString1
  • 2
3 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 33662244
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.

Fernando

0
 

Author Comment

by:ToString1
ID: 33662578
Ok

Table called USER

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

0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 33663011
Hi ToString1;

This should do what you want.

Fernando
// 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

    usersDb.SubmitChanges();

}

else

{

    // Username, password or both are incorrect

    Response.Write("Invalid Username, Password or both.");

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 IIS and Windows Authentication to SQL 21 53
Data is not showing from images 15 36
C# Json POSt to Rest API 4 32
What .NET URL re-routing tool did I use? 2 31
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now