- raise ArgumentError, "pw_hash(): first argument must be a string" unless args[0].is_a? String or args[0].nil?
- raise ArgumentError, "pw_hash(): second argument must be a string" unless args[1].is_a? String
- hashes = { 'md5' => '1',
- 'sha-256' => '5',
- 'sha-512' => '6' }
- hash_type = hashes[args[1].downcase]
- raise ArgumentError, "pw_hash(): #{args[1]} is not a valid hash type" if hash_type.nil?
- raise ArgumentError, "pw_hash(): third argument must be a string" unless args[2].is_a? String
- raise ArgumentError, "pw_hash(): third argument must not be empty" if args[2].empty?
- raise ArgumentError, "pw_hash(): characters in salt must be in the set [a-zA-Z0-9./]" unless args[2].match(/\A[a-zA-Z0-9.\/]+\z/)
+ end
+ raise ArgumentError, 'pw_hash(): first argument must be a string' unless args[0].is_a?(String) || args[0].nil?
+ raise ArgumentError, 'pw_hash(): second argument must be a string' unless args[1].is_a? String
+ hashes = { 'md5' => '1',
+ 'sha-256' => '5',
+ 'sha-512' => '6' }
+ hash_type = hashes[args[1].downcase]
+ raise ArgumentError, "pw_hash(): #{args[1]} is not a valid hash type" if hash_type.nil?
+ raise ArgumentError, 'pw_hash(): third argument must be a string' unless args[2].is_a? String
+ raise ArgumentError, 'pw_hash(): third argument must not be empty' if args[2].empty?
+ raise ArgumentError, 'pw_hash(): characters in salt must be in the set [a-zA-Z0-9./]' unless args[2] =~ %r{\A[a-zA-Z0-9./]+\z}