Solved

need linq code snippet to change password

Posted on 2010-09-13
3
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

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 63

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net web app 3 52
RestClient.cs fails at (HttpWebResponse)request.GetResponse()) 4 45
EF5: Update Model from Database not working 3 66
search by any word in column 5 25
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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