public string Login(string userName, string password) { using (ISession sess = HbmSessionFactory.OpenSession()) { try { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); string md5_password = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(password))); md5_password = md5_password.Replace("-", ""); Officer u = sess.CreateQuery("from Officer where Code=:uCode and Password=:Pwd") .SetParameter <string>("uCode", userName) .SetParameter <string>("Pwd", md5_password) .UniqueResult <Officer>(); if (u != null) { //加载用户所属机构和角色 NHibernateUtil.Initialize(u.Organization); //NHibernateUtil.Initialize(u.Role); string json = JsonSerializerHelper.EntityToJson(u); return(PackJsonResult("true", json, string.Empty)); } else { return(this.PackJsonResult("false", "null", "用户名或密码不正确")); } } catch (Exception ex) { return(this.PackJsonResult("false", "null", ex.Message)); } } }
public static void UnloadHbmDb(params ISession[] hbmSessions) { if (hbmSessions != null && hbmSessions.Length > 0) { foreach (var session in hbmSessions.Where(session => session != null)) { if (session.IsOpen) { session.Close(); } session.Dispose(); } } if (HbmSessionFactory != null) { if (!HbmSessionFactory.IsClosed) { HbmSessionFactory.Close(); } HbmSessionFactory.Dispose(); } HbmCfg = null; HbmSessionFactory = null; }