Solved

need linq code snippet to change password

Posted on 2010-09-13
3
507 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

12 Experts available now in Live!

Get 1:1 Help Now