<commit_before>package models

import (
	"database/sql"

	"github.com/techjanitor/pram-post/config"
	e "github.com/techjanitor/pram-post/errors"
	u "github.com/techjanitor/pram-post/utils"
)

// loginmodel contains user name and password
type LoginModel struct {
	Name     string
	Password string
	Id       uint
	Hash     []byte
}

// Validate will check the provided name and password
func (r *LoginModel) Validate() (err error) {

	// Validate name input
	name := u.Validate{Input: r.Name, Max: config.Settings.Limits.NameMaxLength, Min: config.Settings.Limits.NameMinLength}
	if name.IsEmpty() {
		return e.ErrNameEmpty
	} else if name.MinLength() {
		return e.ErrNameShort
	} else if name.MaxLength() {
		return e.ErrNameLong
	} else if !name.IsUsername() {
		return e.ErrNameAlphaNum
	}

	// Validate password input
	password := u.Validate{Input: r.Password, Max: config.Settings.Limits.NameMaxLength, Min: config.Settings.Limits.NameMinLength}
	if password.IsEmpty() {
		return e.ErrPasswordEmpty
	} else if password.MinLength() {
		return e.ErrPasswordShort
	} else if password.MaxLength() {
		return e.ErrPasswordLong
	}

	return

}

// query user info from database
func (r *LoginModel) Query() (err error) {

	// Get Database handle
	db, err := u.GetDb()
	if err != nil {
		return e.ErrInternalError
	}

	// get hashed password from database
	err = db.QueryRow("select user_id, user_password, usergroup_id from users where user_name = ?", r.Name).Scan(&r.Id, &r.Hash)
	if err == sql.ErrNoRows {
		return e.ErrInvalidUser
	} else if err != nil {
		return e.ErrInternalError
	}

	return

}<commit_msg>add bool checking to user info<commit_after>package models

import (
	"database/sql"

	"github.com/techjanitor/pram-post/config"
	e "github.com/techjanitor/pram-post/errors"
	u "github.com/techjanitor/pram-post/utils"
)

// loginmodel contains user name and password
type LoginModel struct {
	Name     string
	Password string
	Id       uint
	Hash     []byte
}

// Validate will check the provided name and password
func (r *LoginModel) Validate() (err error) {

	// Validate name input
	name := u.Validate{Input: r.Name, Max: config.Settings.Limits.NameMaxLength, Min: config.Settings.Limits.NameMinLength}
	if name.IsEmpty() {
		return e.ErrNameEmpty
	} else if name.MinLength() {
		return e.ErrNameShort
	} else if name.MaxLength() {
		return e.ErrNameLong
	} else if !name.IsUsername() {
		return e.ErrNameAlphaNum
	}

	// Validate password input
	password := u.Validate{Input: r.Password, Max: config.Settings.Limits.NameMaxLength, Min: config.Settings.Limits.NameMinLength}
	if password.IsEmpty() {
		return e.ErrPasswordEmpty
	} else if password.MinLength() {
		return e.ErrPasswordShort
	} else if password.MaxLength() {
		return e.ErrPasswordLong
	}

	return

}

// query user info from database
func (r *LoginModel) Query() (err error) {

	// Get Database handle
	db, err := u.GetDb()
	if err != nil {
		return e.ErrInternalError
	}

	// get hashed password from database
	err = db.QueryRow("select user_id, user_password from users where user_name = ?", r.Name).Scan(&r.Id, &r.Hash)
	if err == sql.ErrNoRows {
		return e.ErrInvalidUser
	} else if err != nil {
		return e.ErrInternalError
	}

	return

}
{'fraction_non_alphanumeric': 0.11393977025768395, 'fraction_numerical': 0.0, 'mean_word_length': 3.759231905465288, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2797139', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1083, 'n_words': 292}