//#import DigestUtil.js
//#import $owl_mall_setting:services/modelService.jsx

var LoginUtil = (function () {
    var f = {
        checkLogin: function (user, password) {
            if (user.isEnable != "1") {
                //用户未激活
                return "1"
            }
            if (!user.passwordhash || !user.random) {
                //密码为设置
                return "2"
            }
            var passwordhash;
            if (user.pwdV == "v1") {
                passwordhash = DigestUtil.digestString(password + user.random, "SHA");
            } else {
                passwordhash = DigestUtil.sha1(password + user.random);
            }
            if (passwordhash != user.passwordhash) {
                //密码错误
                return "3";
            }

            return "0";
        },
        checkEwalletPayPassword: function (jEwallet, password) {
            if (!jEwallet.pay_passwordhash || !jEwallet.pay_random) {
                //密码为设置
                return "2"
            }
            var passwordhash = DigestUtil.sha1(password + jEwallet.pay_random);
            if (passwordhash != jEwallet.pay_passwordhash) {
                //密码错误
                return "3";
            }

            return "0";
        }
    }
    return f;
})();

