// // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to You under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // using System; using System.Data; using System.Data.SqlClient; using System.Text; using Trade.PassiveStsIDal; using Trade.PassiveStsModelClasses; using Trade.Utility; namespace Trade.PassiveStsDalSqlServer { public class Customer : ICustomer { #region "Parameter Constants" private const string PARM_USERID = "@UserId"; #endregion #region "SQL Statement Constants" private const string SQL_SELECT_CUSTOMERPROFILE_BYUSERID = "Set NOCOUNT ON; SELECT accountprofile.USERID, accountprofile.PASSWORD FROM dbo.accountprofile WITH (NOLOCK) WHERE accountprofile.USERID = @UserId"; #endregion private SqlConnection _internalConnection = null; #region IUser Members public void Open(string connectionString) { if (_internalConnection == null) { _internalConnection = new SqlConnection(connectionString); _internalConnection.Open(); } if ((_internalConnection.State == ConnectionState.Broken) || (_internalConnection.State == ConnectionState.Closed)) { _internalConnection.Open(); } } public AccountDataModel login(string userid, string password) { try { SqlParameter parm1 = new SqlParameter(PARM_USERID, SqlDbType.VarChar, 20); parm1.Value = userid; SqlDataReader rdr = SQLServerHelper.ExecuteReaderSingleRowSingleParm(_internalConnection, null, CommandType.Text, SQL_SELECT_CUSTOMERPROFILE_BYUSERID, parm1); if (rdr.Read()) { string userPassword = rdr.GetString(1); rdr.Close(); if (userPassword.Equals(password)) { AccountDataModel customer = new AccountDataModel(userid); return customer; } rdr.Close(); } return null; } catch { throw; } } public void Close() { if (_internalConnection != null && _internalConnection.State != ConnectionState.Closed) _internalConnection.Close(); } #endregion } }